]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
update of the package
authorsrn <srn@opencascade.com>
Mon, 6 Feb 2006 10:58:12 +0000 (10:58 +0000)
committersrn <srn@opencascade.com>
Mon, 6 Feb 2006 10:58:12 +0000 (10:58 +0000)
45 files changed:
src/SVTK/Makefile.in
src/SVTK/SALOME_Actor.cxx [new file with mode: 0644]
src/SVTK/SALOME_Actor.h [new file with mode: 0644]
src/SVTK/SVTK.cxx [new file with mode: 0644]
src/SVTK/SVTK_Actor.cxx
src/SVTK/SVTK_Actor.h
src/SVTK/SVTK_CubeAxesDlg.cxx [new file with mode: 0644]
src/SVTK/SVTK_CubeAxesDlg.h [new file with mode: 0644]
src/SVTK/SVTK_DeviceActor.cxx [new file with mode: 0644]
src/SVTK/SVTK_DeviceActor.h [new file with mode: 0644]
src/SVTK/SVTK_Event.h [new file with mode: 0644]
src/SVTK/SVTK_FontWidget.cxx [new file with mode: 0644]
src/SVTK/SVTK_FontWidget.h [new file with mode: 0644]
src/SVTK/SVTK_Functor.h
src/SVTK/SVTK_GenericRenderWindowInteractor.cxx [new file with mode: 0644]
src/SVTK/SVTK_GenericRenderWindowInteractor.h [new file with mode: 0644]
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_MainWindow.cxx [new file with mode: 0644]
src/SVTK/SVTK_MainWindow.h [new file with mode: 0644]
src/SVTK/SVTK_NonIsometricDlg.cxx [new file with mode: 0644]
src/SVTK/SVTK_NonIsometricDlg.h [new file with mode: 0644]
src/SVTK/SVTK_RectPicker.cxx [new file with mode: 0644]
src/SVTK/SVTK_RectPicker.h [new file with mode: 0644]
src/SVTK/SVTK_RenderWindow.cxx [deleted file]
src/SVTK/SVTK_RenderWindow.h [deleted file]
src/SVTK/SVTK_RenderWindowInteractor.cxx
src/SVTK/SVTK_RenderWindowInteractor.h
src/SVTK/SVTK_Renderer.cxx [new file with mode: 0644]
src/SVTK/SVTK_Renderer.h [new file with mode: 0644]
src/SVTK/SVTK_Selection.h
src/SVTK/SVTK_SelectionEvent.h [new file with mode: 0644]
src/SVTK/SVTK_Selector.cxx
src/SVTK/SVTK_Selector.h
src/SVTK/SVTK_SelectorDef.h
src/SVTK/SVTK_SpaceMouse.cxx [new file with mode: 0644]
src/SVTK/SVTK_SpaceMouse.h [new file with mode: 0644]
src/SVTK/SVTK_View.cxx [new file with mode: 0644]
src/SVTK/SVTK_View.h [new file with mode: 0644]
src/SVTK/SVTK_ViewManager.h
src/SVTK/SVTK_ViewModel.cxx
src/SVTK/SVTK_ViewModel.h
src/SVTK/SVTK_ViewModelBase.h [new file with mode: 0644]
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h

index c395159b71b38bee515a8aaa3b77cc0361da5e0d..58c7e6fdb0843cda861f4a555fa8e2b21a4766c8 100755 (executable)
@@ -1,7 +1,7 @@
 #  File   : Makefile.in
 #  Author : Alexander Solovyov(OCN)
 #  Module : SVTK
-# $Header: /dn06/SALOME_CVS/GUI_SRC/src/SVTK/Makefile.in,v 1.1
+# $Header: 
 
 top_srcdir=@top_srcdir@
 top_builddir=../..
@@ -12,47 +12,88 @@ VPATH=.:@srcdir@:@srcdir@/resources
 @COMMENCE@
 
 # header files
-EXPORT_HEADERS= SVTK.h \
-               SVTK_Prs.h \
-               SVTK_Actor.h \
-               SVTK_CubeAxesActor2D.h \
-               SVTK_Functor.h \
-               SVTK_ViewManager.h \
-               SVTK_ViewModel.h \
-               SVTK_ViewWindow.h \
-               SVTK_RenderWindow.h \
-               SVTK_InteractorStyle.h \
-               SVTK_RenderWindowInteractor.h \
-               SVTK_Selector.h \
-               SVTK_Selection.h
+EXPORT_HEADERS= \
+       SVTK.h \
+       SVTK_Prs.h \
+       SVTK_Actor.h \
+       SALOME_Actor.h \
+       SVTK_RectPicker.h \
+       SVTK_DeviceActor.h \
+       SVTK_FontWidget.h \
+       SVTK_CubeAxesActor2D.h \
+       SVTK_Functor.h \
+       SVTK_MainWindow.h \
+       SVTK_View.h \
+       SVTK_ViewManager.h \
+       SVTK_ViewModel.h \
+       SVTK_ViewWindow.h \
+       SVTK_Renderer.h \
+       SVTK_InteractorStyle.h \
+       SVTK_RenderWindowInteractor.h \
+       SVTK_GenericRenderWindowInteractor.h \
+       SVTK_Selector.h \
+       SVTK_Selection.h \
+       SVTK_SelectionEvent.h \
+       SVTK_SpaceMouse.h \
+       SVTK_Event.h \
+       SVTK_ViewModelBase.h
 
 PO_FILES = SVTK_msg_en.po
 
 # Libraries targets
 LIB = libSVTK.la
 
-LIB_SRC=       SVTK_Prs.cxx \
-               SVTK_Actor.cxx \
-               SVTK_CubeAxesActor2D.cxx \
-               SVTK_Trihedron.cxx \
-               SVTK_ViewManager.cxx \
-               SVTK_ViewModel.cxx \
-               SVTK_ViewWindow.cxx \
-               SVTK_RenderWindow.cxx \
-               SVTK_InteractorStyle.cxx \
-               SVTK_RenderWindowInteractor.cxx \
-               SVTK_Selector.cxx
-
-LIB_MOC =      SVTK_RenderWindowInteractor.h \
-               SVTK_InteractorStyle.h \
-               SVTK_RenderWindow.h \
-               SVTK_ViewWindow.h \
-               SVTK_ViewModel.h \
-               SVTK_ViewManager.h
-
-CPPFLAGS+=$(QT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(BOOST_CPPFLAGS)
-
-LDFLAGS+=$(QT_MT_LIBS) $(OCC_LIBS) $(VTK_LIBS)
-LIBS+= -lsuit -lCAM -lSalomeObject -lSalomePrs -lVTKViewer
+LIB_SRC= \
+       SVTK_Prs.cxx \
+       SVTK_Actor.cxx \
+       SALOME_Actor.cxx \
+       SVTK_RectPicker.cxx \
+       SVTK_DeviceActor.cxx \
+       SVTK_CubeAxesActor2D.cxx \
+       SVTK_NonIsometricDlg.cxx \
+       SVTK_CubeAxesDlg.cxx \
+       SVTK_FontWidget.cxx \
+       SVTK_Trihedron.cxx \
+       SVTK_MainWindow.cxx \
+       SVTK_View.cxx \
+       SVTK_ViewManager.cxx \
+       SVTK_ViewModel.cxx \
+       SVTK_Renderer.cxx \
+       SVTK_ViewWindow.cxx \
+       SVTK_InteractorStyle.cxx \
+       SVTK_RenderWindowInteractor.cxx \
+       SVTK_GenericRenderWindowInteractor.cxx \
+       SVTK_SpaceMouse.cxx \
+       SVTK_Selector.cxx
+
+LIB_MOC = \
+       SVTK_GenericRenderWindowInteractor.h \
+       SVTK_RenderWindowInteractor.h \
+       SVTK_NonIsometricDlg.h \
+       SVTK_CubeAxesDlg.h \
+       SVTK_FontWidget.h \
+       SVTK_ViewModelBase.h \
+       SVTK_ViewManager.h \
+       SVTK_ViewWindow.h \
+       SVTK_MainWindow.h \
+       SVTK_ViewModel.h \
+       SVTK_View.h
+
+BIN = SVTK
+
+CPPFLAGS+= \
+       $(QT_INCLUDES) \
+       $(OCC_INCLUDES) \
+       $(VTK_INCLUDES) \
+       $(BOOST_CPPFLAGS)
+
+LDFLAGS+= \
+       $(QT_MT_LIBS) \
+       $(OCC_LIBS) \
+       $(VTK_LIBS)
+
+LIBS+= -lqtx -lsuit -lstd -lCAM -lSalomeObject -lSalomePrs -lVTKViewer
+
+LDFLAGSFORBIN=$(LDFLAGS) $(LIBS)
 
 @CONCLUDE@
diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx
new file mode 100644 (file)
index 0000000..9b1b793
--- /dev/null
@@ -0,0 +1,743 @@
+//  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SALOME_Actor.cxx
+//  Author : Nicolas REJNERI
+//  Module : SALOME
+//  $Header$
+
+/*!
+  \class SALOME_Actor SALOME_Actor.h
+  \brief Abstract class of SALOME Objects in VTK.
+*/
+
+
+#include "SALOME_Actor.h"
+
+#include "VTKViewer_Transform.h"
+#include "VTKViewer_TransformFilter.h"
+#include "VTKViewer_PassThroughFilter.h"
+#include "VTKViewer_GeometryFilter.h"
+#include "SVTK_RectPicker.h"
+
+#include "SVTK_Actor.h"
+
+// VTK Includes
+#include <vtkCell.h>
+#include <vtkLine.h>
+#include <vtkPicker.h>
+#include <vtkPointPicker.h>
+#include <vtkCellPicker.h>
+#include <vtkRenderer.h>
+#include <vtkPolyData.h>
+#include <vtkObjectFactory.h>
+#include <vtkDataSetMapper.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkProperty.h>
+#include <vtkOutlineSource.h>
+
+#include <vtkInteractorStyle.h>
+#include <vtkRenderWindowInteractor.h>
+
+#include <TColStd_MapOfInteger.hxx>
+#include <TColStd_IndexedMapOfInteger.hxx>
+
+using namespace std;
+
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#endif
+
+int SALOME_POINT_SIZE = 5;
+int SALOME_LINE_WIDTH = 3;
+
+//----------------------------------------------------------------------------
+namespace
+{
+  int
+  GetEdgeId(SALOME_Actor* theActor,
+           vtkPicker* thePicker, 
+           int theObjId)
+  {
+    int anEdgeId = 0;
+    if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
+      float aPickPosition[3];
+      thePicker->GetPickPosition(aPickPosition);
+      float aMinDist = 1000000.0, aDist = 0;
+      for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
+       if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
+         int subId;  float pcoords[3], closestPoint[3], weights[3];
+         aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
+         if (aDist < aMinDist) {
+           aMinDist = aDist;
+           anEdgeId = -1 - i;
+         }
+       }
+      }
+    }
+    return anEdgeId;
+  }
+
+  inline
+  bool
+  CheckDimensionId(Selection_Mode theMode, 
+                  SALOME_Actor *theActor, 
+                  vtkIdType theObjId)
+  {
+    switch(theMode){
+    case CellSelection:
+      return true;
+    case EdgeSelection:
+      return ( theActor->GetObjDimension( theObjId ) == 1 );
+    case FaceSelection:
+      return ( theActor->GetObjDimension( theObjId ) == 2 );
+    case VolumeSelection:
+      return ( theActor->GetObjDimension( theObjId ) == 3 );
+    };
+    return false;
+  }
+
+}
+
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(SALOME_Actor);
+
+
+//----------------------------------------------------------------------------
+SALOME_Actor
+::SALOME_Actor():
+  myRenderer(NULL),
+  myInteractor(NULL),
+  mySelectionMode(ActorSelection),
+  myPreHighlightActor(SVTK_Actor::New()),
+  myHighlightActor(SVTK_Actor::New()),
+  myOutline(vtkOutlineSource::New()),
+  myOutlineActor(VTKViewer_Actor::New())
+{
+  myPreHighlightActor->Delete();
+  myPreHighlightActor->Initialize();
+  myPreHighlightActor->PickableOff();
+  myPreHighlightActor->SetVisibility( false );
+
+  myHighlightActor->Delete();
+  myHighlightActor->Initialize();
+  myHighlightActor->PickableOff();
+  myHighlightActor->SetVisibility( false );
+
+  myOutline->Delete();
+
+  vtkPolyDataMapper* anOutlineMapper = vtkPolyDataMapper::New();
+  anOutlineMapper->SetInput(myOutline->GetOutput());
+
+  myOutlineActor->Delete();
+  myOutlineActor->SetMapper( anOutlineMapper );
+  anOutlineMapper->Delete();
+
+  myOutlineActor->PickableOff();
+  myOutlineActor->DragableOff();
+  myOutlineActor->GetProperty()->SetColor(1.0,0.0,0.0);
+  myOutlineActor->GetProperty()->SetAmbient(1.0);
+  myOutlineActor->GetProperty()->SetDiffuse(0.0);
+  myOutlineActor->SetVisibility( false );
+}
+
+
+//----------------------------------------------------------------------------
+SALOME_Actor
+::~SALOME_Actor()
+{}
+
+
+//----------------------------------------------------------------------------
+Standard_Boolean 
+SALOME_Actor
+::hasIO() 
+{ 
+  return !myIO.IsNull(); 
+}
+
+const Handle(SALOME_InteractiveObject)& 
+SALOME_Actor
+::getIO()
+{ 
+  return myIO; 
+}
+
+void
+SALOME_Actor
+::setIO(const Handle(SALOME_InteractiveObject)& theIO) 
+{ 
+  myIO = theIO; 
+}
+
+void
+SALOME_Actor
+::setName(const char* theName)
+{
+  if(hasIO())  
+    myIO->setName(theName);
+  Superclass::setName(theName);
+}
+
+
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::AddToRender(vtkRenderer* theRenderer)
+{
+  Superclass::AddToRender(theRenderer);
+
+  myRenderer = theRenderer;
+
+  theRenderer->AddActor( myPreHighlightActor.GetPointer() );
+  theRenderer->AddActor( myHighlightActor.GetPointer() );
+  theRenderer->AddActor( myOutlineActor.GetPointer() );
+}
+
+void 
+SALOME_Actor
+::RemoveFromRender(vtkRenderer* theRenderer)
+{
+  Superclass::RemoveFromRender(theRenderer);
+
+  theRenderer->RemoveActor( myPreHighlightActor.GetPointer() );
+  theRenderer->RemoveActor( myHighlightActor.GetPointer() );
+  theRenderer->RemoveActor( myOutlineActor.GetPointer() );
+}
+
+vtkRenderer*
+SALOME_Actor
+::GetRenderer()
+{
+  return myRenderer;
+}
+
+
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::SetInteractor(vtkRenderWindowInteractor* theInteractor)
+{
+  myInteractor = theInteractor;
+}
+
+void
+SALOME_Actor
+::Update()
+{
+  myInteractor->CreateTimer(VTKI_TIMER_UPDATE);    
+}
+
+
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::SetTransform(VTKViewer_Transform* theTransform)
+{
+  Superclass::SetTransform(theTransform);
+
+  myPreHighlightActor->SetTransform(theTransform);
+  myHighlightActor->SetTransform(theTransform);
+  myOutlineActor->SetTransform(theTransform);
+}
+
+
+void
+SALOME_Actor
+::SetPosition(float _arg1, float _arg2, float _arg3)
+{
+  Superclass::SetPosition(_arg1,_arg2,_arg3);
+
+  myPreHighlightActor->SetPosition(_arg1,_arg2,_arg3);
+  myHighlightActor->SetPosition(_arg1,_arg2,_arg3);
+  myOutlineActor->SetPosition(_arg1,_arg2,_arg3);
+}
+
+
+void
+SALOME_Actor
+::SetPosition(float _arg[3])
+{
+  SetPosition(_arg[0],_arg[1],_arg[2]);
+}
+
+
+//----------------------------------------------------------------
+void
+SALOME_Actor
+::SetVisibility( int theVisibility )
+{
+  Superclass::SetVisibility( theVisibility );
+
+  myOutlineActor->SetVisibility( theVisibility && isHighlighted() && !hasHighlight() );
+
+  myPreHighlightActor->SetVisibility( theVisibility && myIsPreselected );
+
+  if(mySelector.GetPointer() && hasIO()){
+    if(mySelector->SelectionMode() != ActorSelection){
+      int aHasIndex = mySelector->HasIndex( getIO() );
+      myHighlightActor->SetVisibility( theVisibility && isHighlighted() && aHasIndex);
+    }
+  }
+}
+
+
+//----------------------------------------------------------------
+void
+SALOME_Actor
+::SetSelector(SVTK_Selector* theSelector)
+{
+  mySelector = theSelector;
+}
+
+void
+SALOME_Actor
+::Highlight(bool theIsHighlight)
+{
+  mySelectionMode = mySelector->SelectionMode();
+  myHighlightActor->SetVisibility( false );
+  myOutlineActor->SetVisibility( false );
+
+  if(mySelector.GetPointer()){
+    if(mySelectionMode != ActorSelection){
+      TColStd_IndexedMapOfInteger aMapIndex;
+      mySelector->GetIndex( getIO(), aMapIndex );
+      switch( mySelectionMode ){
+      case NodeSelection:
+       myHighlightActor->GetProperty()->SetRepresentationToPoints();
+       myHighlightActor->MapPoints( this, aMapIndex );
+       break;
+      case EdgeOfCellSelection:
+       myHighlightActor->GetProperty()->SetRepresentationToWireframe();
+       myHighlightActor->MapEdge( this, aMapIndex );
+       break;
+      case CellSelection:
+      case EdgeSelection:
+      case FaceSelection:
+      case VolumeSelection:
+       myHighlightActor->GetProperty()->SetRepresentationToSurface();
+       myHighlightActor->MapCells( this, aMapIndex );
+       break;
+      }
+      myHighlightActor->SetVisibility( GetVisibility() && theIsHighlight );
+    }
+  }
+
+  highlight(theIsHighlight);
+}
+
+void
+SALOME_Actor
+::highlight(bool theIsHighlight)
+{
+  float aBounds[6];
+  GetInput()->GetBounds(aBounds);
+  myOutline->SetBounds(aBounds);
+  myOutlineActor->SetVisibility( GetVisibility() && theIsHighlight );
+
+  Superclass::highlight(theIsHighlight);
+}
+
+
+//----------------------------------------------------------------
+bool
+SALOME_Actor
+::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
+              SVTK_SelectionEvent* theSelectionEvent,
+              bool theIsHighlight)
+{
+  vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
+  //
+  myPreHighlightActor->SetVisibility( false );
+  bool anIsPreselected = myIsPreselected;
+  
+  Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
+  bool anIsChanged = (mySelectionMode != aSelectionMode);
+
+  float x = theSelectionEvent->myX;
+  float y = theSelectionEvent->myY;
+  float z = 0.0;
+
+  if( !theIsHighlight ) {
+    SetPreSelected( false );
+    vtkActorCollection* theActors = aRenderer->GetActors();
+    theActors->InitTraversal();
+    while( vtkActor *ac = theActors->GetNextActor() )
+      if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) )
+       if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
+         anActor->SetPreSelected( false );
+
+  }else{
+    switch(aSelectionMode){
+    case NodeSelection: 
+    {
+      myPointPicker->Pick( x, y, z, aRenderer );
+      
+      int aVtkId = myPointPicker->GetPointId();
+      if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
+       int anObjId = GetNodeObjId( aVtkId );
+       myIsPreselected = (anObjId >= 0);
+       if(myIsPreselected){
+         const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+         int anExtent = aMapIndex.Extent();
+         anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1));
+         if(anIsChanged){
+           TColStd_IndexedMapOfInteger aMapIndex;
+           aMapIndex.Add( anObjId );
+           
+           myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
+           myPreHighlightActor->MapPoints( this, aMapIndex );
+         }
+         myPreHighlightActor->SetVisibility( true );
+       }
+      }
+      break;
+    }
+    case CellSelection: 
+    case EdgeSelection:
+    case FaceSelection:
+    case VolumeSelection: 
+    {
+      myCellPicker->Pick( x, y, z, aRenderer );
+      
+      int aVtkId = myCellPicker->GetCellId();
+      if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) {
+       int anObjId = GetElemObjId (aVtkId );
+       if ( anObjId >= 0 ) {
+         myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId);
+         if(myIsPreselected){
+           const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+           int anExtent = aMapIndex.Extent();
+           anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1));
+           if(anIsChanged){
+             TColStd_IndexedMapOfInteger aMapIndex;
+             aMapIndex.Add( anObjId );
+             
+             myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
+             myPreHighlightActor->MapCells( this, aMapIndex );
+           }
+           myPreHighlightActor->SetVisibility( true );
+         }
+       }
+      }
+      break;
+    }
+    case EdgeOfCellSelection:
+    {
+      myCellPicker->Pick( x, y, z, aRenderer );
+      
+      int aVtkId = myCellPicker->GetCellId();
+      if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId )) {
+       int anObjId = GetElemObjId( aVtkId );
+       if ( anObjId >= 0 ) {
+         int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
+         myIsPreselected = anEdgeId < 0;
+         if(myIsPreselected){
+           const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+           int anExtent = aMapIndex.Extent();
+           anIsChanged |= (anExtent == 0);
+           anIsChanged |= (anExtent == 2 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2)));
+           if(anIsChanged){
+             TColStd_IndexedMapOfInteger aMapIndex;
+             aMapIndex.Add( anObjId );
+             aMapIndex.Add( anEdgeId );
+
+             myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
+             myPreHighlightActor->MapEdge( this, aMapIndex );
+           }
+           myPreHighlightActor->SetVisibility( true );
+         }
+       }
+      }
+      break;
+    }
+    case ActorSelection : 
+    {
+      if( !mySelector->IsSelected( myIO ) ) {
+       SetPreSelected( true );
+
+       vtkActorCollection* theActors = aRenderer->GetActors();
+       theActors->InitTraversal();
+       while( vtkActor *anAct = theActors->GetNextActor() ) {
+         if( anAct != this )
+           if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( anAct ) )
+             if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
+               anActor->SetPreSelected( true );
+       }
+      }
+    }
+    default:
+      break;
+    }
+  }
+
+  mySelectionMode = aSelectionMode;
+  anIsChanged |= (anIsPreselected != myIsPreselected);
+
+  return anIsChanged;
+}
+
+
+//----------------------------------------------------------------
+bool
+SALOME_Actor
+::Highlight(vtkInteractorStyle *theInteractorStyle, 
+           SVTK_SelectionEvent* theSelectionEvent,
+           bool theIsHighlight)
+{
+  myOutlineActor->SetVisibility( false );
+  myHighlightActor->SetVisibility( false );
+
+  vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
+  //
+  Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
+  bool anIsShift = theSelectionEvent->myIsShift;
+  if( !anIsShift ) {
+    mySelector->RemoveIObject( this );
+  }
+
+  float x = theSelectionEvent->myX;
+  float y = theSelectionEvent->myY;
+  float z = 0.0;
+
+  if( !theSelectionEvent->myIsRectangle ) {
+    switch(aSelectionMode){
+    case NodeSelection: {
+      myPointPicker->Pick( x, y, z, aRenderer );
+
+      int aVtkId = myPointPicker->GetPointId();
+      if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
+       int anObjId = GetNodeObjId( aVtkId );
+       if( anObjId >= 0 ) {
+         mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
+         mySelector->AddIObject( this );
+       }
+      }
+      break;
+    }
+    case CellSelection: 
+    case EdgeSelection:
+    case FaceSelection:
+    case VolumeSelection: 
+    {
+      myCellPicker->Pick( x, y, z, aRenderer );
+    
+      int aVtkId = myCellPicker->GetCellId();
+      if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
+       int anObjId = GetElemObjId( aVtkId );
+       if( anObjId >= 0 ) {
+         if ( CheckDimensionId(aSelectionMode,this,anObjId) ) {
+           mySelector->AddOrRemoveIndex( myIO, anObjId, anIsShift );
+           mySelector->AddIObject( this );
+         }
+       }
+      }
+      break;
+    }
+    case EdgeOfCellSelection: 
+    {
+      myCellPicker->Pick( x, y, z, aRenderer );
+    
+      int aVtkId = myCellPicker->GetCellId();
+      if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
+       int anObjId = GetElemObjId( aVtkId );
+       if( anObjId >= 0 ) {
+         int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
+         if( anEdgeId < 0 ) {
+           mySelector->AddOrRemoveIndex( myIO, anObjId, false );
+           mySelector->AddOrRemoveIndex( myIO, anEdgeId, true );
+           mySelector->AddIObject( this );
+         } 
+       }
+      }
+      break;
+    }
+    case ActorSelection : 
+    {
+      if( mySelector->IsSelected( myIO ) && anIsShift )
+       mySelector->RemoveIObject( this );
+      else {
+       mySelector->AddIObject( this );
+      }
+      break;
+    }
+    default:
+      break;
+    }
+  }else{
+    float xLast = theSelectionEvent->myLastX;
+    float yLast = theSelectionEvent->myLastY;
+    float zLast = 0.0;
+
+    float x1 = x < xLast ? x : xLast;
+    float y1 = y < yLast ? y : yLast;
+    float z1 = z < zLast ? z : zLast;
+    float x2 = x > xLast ? x : xLast;
+    float y2 = y > yLast ? y : yLast;
+    float z2 = z > zLast ? z : zLast;
+
+    switch(aSelectionMode){
+    case NodeSelection: {
+      myPointRectPicker->InitializePickList();
+      myPointRectPicker->AddPickList(this);
+      myPointRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
+
+      const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myPointRectPicker->GetPointIdsMap();
+      SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
+      TColStd_MapOfInteger anIndexes;
+      if(aMapIter != aVectorIdsMap.end()){
+       const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
+       vtkIdType anEnd = aVectorIds.size();
+       SVTK_RectPicker::TVectorIds::const_iterator anIdIter = aVectorIds.begin();
+       for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
+         int aPointId = aVectorIds[anId];
+         if( aPointId >= 0 && mySelector->IsValid( this, aPointId, true ) ) {
+           int anObjId = GetNodeObjId( aPointId );
+           anIndexes.Add( anObjId );
+         }
+       }
+      }
+      
+      if( !anIndexes.IsEmpty() ) {
+       mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
+       mySelector->AddIObject( this );
+       anIndexes.Clear();
+      }
+      else
+       mySelector->RemoveIObject( this );
+
+      break;
+    }
+    case ActorSelection :
+    {
+      float aPnt[3];
+      float* aBounds = GetBounds();
+
+      bool anIsPicked = true;
+      for( int i = 0; i <= 1; i++ ) {
+       for( int j = 2; j <= 3; j++ ) {
+         for( int k = 4; k <= 5; k++ ) {
+           aRenderer->SetWorldPoint( aBounds[ i ], aBounds[ j ], aBounds[ k ], 1.0 );
+           aRenderer->WorldToDisplay();
+           aRenderer->GetDisplayPoint( aPnt );
+
+           if( aPnt[0] < x1 || aPnt[0] > x2 || aPnt[1] < y1 || aPnt[1] > y2 ) {
+             anIsPicked = false;
+             break;
+           }
+         }
+       }
+      }
+
+      if( anIsPicked )
+       mySelector->AddIObject(this);
+
+      break;
+    }
+    case CellSelection: 
+    case EdgeSelection:
+    case FaceSelection:
+    case VolumeSelection: 
+    {
+      myCellRectPicker->InitializePickList();
+      myCellRectPicker->AddPickList(this);
+      myCellRectPicker->Pick( x1, y1, z1, x2, y2, z2, aRenderer );
+
+      const SVTK_RectPicker::TVectorIdsMap& aVectorIdsMap = myCellRectPicker->GetCellIdsMap();
+      SVTK_RectPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
+      TColStd_MapOfInteger anIndexes;
+      if(aMapIter != aVectorIdsMap.end()){
+       const SVTK_RectPicker::TVectorIds& aVectorIds = aMapIter->second;
+       vtkIdType anEnd = aVectorIds.size();
+       SVTK_RectPicker::TVectorIds::const_iterator anIdIter = aVectorIds.begin();
+       for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
+         int aCellId = aVectorIds[anId];
+         if ( !mySelector->IsValid( this, aCellId ) )
+           continue;
+
+         int anObjId = GetElemObjId( aCellId );
+         if( anObjId != -1 )
+           if ( CheckDimensionId(aSelectionMode,this,anObjId) ) {
+             anIndexes.Add(anObjId);
+           }
+       }
+      }
+      mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
+      mySelector->AddIObject( this );
+    }
+    default:
+      break;
+    }
+  }
+
+  mySelectionMode = aSelectionMode;
+
+  return true;
+}
+
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::SetPointPicker(vtkPointPicker* thePointPicker) 
+{
+  myPointPicker = thePointPicker;
+}
+
+void
+SALOME_Actor
+::SetCellPicker(vtkCellPicker* theCellPicker) 
+{
+  myCellPicker = theCellPicker;
+}
+
+void
+SALOME_Actor
+::SetPointRectPicker(SVTK_RectPicker* theRectPicker) 
+{
+  myPointRectPicker = theRectPicker;
+}
+
+void
+SALOME_Actor
+::SetCellRectPicker(SVTK_RectPicker* theRectPicker) 
+{
+  myCellRectPicker = theRectPicker;
+}
+
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::SetPreHighlightProperty(vtkProperty* theProperty) 
+{
+  myPreHighlightActor->SetProperty(theProperty);
+}
+
+void
+SALOME_Actor
+::SetHighlightProperty(vtkProperty* theProperty) 
+{
+  myHighlightActor->SetProperty(theProperty);
+}
diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h
new file mode 100644 (file)
index 0000000..d377ff6
--- /dev/null
@@ -0,0 +1,228 @@
+//  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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
+//
+//
+//
+//  File   : SALOME_Actor.h
+//  Author : Nicolas REJNERI
+//  Module : SALOME
+//  $Header$
+
+#ifndef SALOME_ACTOR_H
+#define SALOME_ACTOR_H
+
+#include "SVTK_SelectionEvent.h"
+#include "SVTK_Selector.h"
+#include "SVTK.h"
+
+#include "SALOME_InteractiveObject.hxx"
+
+// undefining min and max because CASCADE's defines them and
+// it clashes with std::min(), std::max()
+#undef min
+#undef max
+
+#include "VTKViewer_Actor.h"
+
+#include <vtkSmartPointer.h>
+
+class vtkPointPicker;
+class vtkCellPicker;
+class vtkOutlineSource;
+class vtkInteractorStyle;
+class vtkRenderWindowInteractor;
+
+class SVTK_Actor;
+class SVTK_RectPicker;
+class SVTK_InteractorStyle;
+
+extern int SALOME_POINT_SIZE;
+extern int SALOME_LINE_WIDTH;
+
+//! The class is a basic one for all SALOME VTK presentation.
+/*!
+  It provide highlight and prehighlight capabilites,
+  common way to publish and remove VTK presentation, 
+  mapping of VTK and object IDs and so on.
+ */
+class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor 
+{
+ public:
+  static SALOME_Actor* New();
+  
+  vtkTypeMacro(SALOME_Actor,VTKViewer_Actor);
+
+  //----------------------------------------------------------------------------
+  //! To check, if the #SALOME_Actor has a reference to #SALOME_InteractiveObject
+  virtual
+  Standard_Boolean 
+  hasIO();
+
+  //! Get correspoinding reference to #SALOME_InteractiveObject
+  virtual 
+  const Handle(SALOME_InteractiveObject)& 
+  getIO(); 
+
+  //! Set reference to #SALOME_InteractiveObject
+  virtual
+  void
+  setIO(const Handle(SALOME_InteractiveObject)& theIO);
+
+  //! Name the #SALOME_Actor
+  virtual
+  void
+  setName(const char* theName);
+
+  //----------------------------------------------------------------------------
+  //! Apply view transformation
+  virtual
+  void
+  SetTransform(VTKViewer_Transform* theTransform); 
+
+  //! Apply additional position
+  virtual
+  void
+  SetPosition(float _arg1, float _arg2, float _arg3);
+
+  //! Apply additional position
+  virtual
+  void
+  SetPosition(float _arg[3]);
+
+  //----------------------------------------------------------------------------
+  //! Visibility management
+  virtual
+  void
+  SetVisibility( int );
+
+  //----------------------------------------------------------------------------
+  //! To publish the actor an all its internal devices
+  virtual
+  void
+  AddToRender(vtkRenderer* theRendere); 
+
+  //! To remove the actor an all its internal devices
+  virtual
+  void
+  RemoveFromRender(vtkRenderer* theRendere);
+
+  //! Get reference on renderer where it is published
+  vtkRenderer*
+  GetRenderer();
+
+  //----------------------------------------------------------------------------
+  //! To set interactor in order to use #vtkInteractorObserver devices
+  virtual
+  void
+  SetInteractor(vtkRenderWindowInteractor* theInteractor);
+
+  //! Put a request to redraw the view 
+  virtual
+  void
+  Update();
+
+  //----------------------------------------------------------------------------
+  //! Set selector in order to the actor at any time can restore current selection
+  virtual
+  void
+  SetSelector(SVTK_Selector* theSelector);
+
+  //! Just to update visibility of the highlight devices
+  virtual
+  void
+  highlight(bool theHighlight);  
+
+  //! To map current selection to VTK representation
+  virtual
+  void
+  Highlight(bool theHighlight);  
+
+  //----------------------------------------------------------------------------
+  //! To process prehighlight (called from #SVTK_InteractorStyle)
+  virtual
+  bool
+  PreHighlight(vtkInteractorStyle* theInteractorStyle, 
+              SVTK_SelectionEvent* theSelectionEvent,
+              bool theIsHighlight);
+
+  //! To process highlight (called from #SVTK_InteractorStyle)
+  virtual 
+  bool
+  Highlight(vtkInteractorStyle* theInteractorStyle, 
+           SVTK_SelectionEvent* theSelectionEvent,
+           bool theIsHighlight);
+
+  //----------------------------------------------------------------------------
+  //! To set up a picker for nodal selection (initialized by #SVTK_Renderer::AddActor)
+  void
+  SetPointPicker(vtkPointPicker* thePointPicker); 
+
+  //! To set up a picker for cell selection (initialized by #SVTK_Renderer::AddActor)
+  void
+  SetCellPicker(vtkCellPicker* theCellPicker); 
+
+  //! To set up a picker for point rectangle selection (initialized by #SVTK_Renderer::AddActor)
+  void
+  SetPointRectPicker(SVTK_RectPicker* theRectPicker);
+
+  //! To set up a picker for cell rectangle selection (initialized by #SVTK_Renderer::AddActor)
+  void
+  SetCellRectPicker(SVTK_RectPicker* theRectPicker);
+
+  //----------------------------------------------------------------------------
+  //! To set up a prehighlight property (initialized by #SVTK_Renderer::AddActor)
+  void
+  SetPreHighlightProperty(vtkProperty* theProperty);
+
+  //! To set up a highlight property (initialized by #SVTK_Renderer::AddActor)
+  void
+  SetHighlightProperty(vtkProperty* theProperty);
+
+ protected:
+  //----------------------------------------------------------------------------
+  vtkRenderWindowInteractor* myInteractor;
+  vtkRenderer* myRenderer;
+
+  Handle(SALOME_InteractiveObject) myIO;
+
+  SALOME_Actor();
+  ~SALOME_Actor();
+
+ protected:
+  Selection_Mode mySelectionMode;
+  vtkSmartPointer<SVTK_Selector> mySelector;
+
+  //----------------------------------------------------------------------------
+  // Highlight/ Prehighlight devices
+  vtkSmartPointer<vtkPointPicker> myPointPicker;
+  vtkSmartPointer<vtkCellPicker> myCellPicker;
+
+  vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
+  vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
+
+  vtkSmartPointer<SVTK_Actor> myPreHighlightActor;
+  vtkSmartPointer<SVTK_Actor> myHighlightActor;
+
+  vtkSmartPointer<VTKViewer_Actor> myOutlineActor;
+  vtkSmartPointer<vtkOutlineSource> myOutline;
+};
+
+#endif // SALOME_ACTOR_H
diff --git a/src/SVTK/SVTK.cxx b/src/SVTK/SVTK.cxx
new file mode 100644 (file)
index 0000000..0be0d5c
--- /dev/null
@@ -0,0 +1,60 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   :
+//  Author :
+//  Module :
+//  $Header$
+
+#include "SVTK.h"
+#include "SVTK_Prs.h"
+#include "SVTK_Actor.h"
+#include "SALOME_Actor.h"
+#include "SVTK_RectPicker.h"
+#include "SVTK_DeviceActor.h"
+#include "SVTK_CubeAxesActor2D.h"
+#include "SVTK_Functor.h"
+#include "SVTK_View.h"
+#include "SVTK_MainWindow.h"
+#include "SVTK_MainWindow.h"
+#include "SVTK_NonIsometricDlg.h"
+#include "SVTK_CubeAxesDlg.h"
+#include "SVTK_FontWidget.h"
+#include "SVTK_ViewModel.h"
+#include "SVTK_ViewWindow.h"
+#include "SVTK_Renderer.h"
+#include "SVTK_InteractorStyle.h"
+#include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_GenericRenderWindowInteractor.h"
+#include "SVTK_Selector.h"
+#include "SVTK_Selection.h"
+#include "SVTK_SelectionEvent.h"
+#include "SVTK_SpaceMouse.h"
+#include "SVTK_Event.h"
+#include "SVTK_ViewModelBase.h"
+
+int
+main(int argc, char** argv)
+{
+  return 0;
+}
index c958f2852bb760a1448229a2493ec67d333d5b5f..337075bb1a4e8d52e43b9dfba5b3886709200cfc 100644 (file)
@@ -18,8 +18,7 @@
 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
 
 #include "SVTK_Actor.h"
-
-#include "VTKViewer_PassThroughFilter.h"
+#include "SALOME_Actor.h"
 
 // VTK Includes
 #include <vtkObjectFactory.h>
 
 #include <vtkCell.h>
 #include <vtkPolyData.h>
-#include <vtkShrinkFilter.h>
 
 using namespace std;
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
-
 
-static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){
+static 
+void
+CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
+{
   vtkPoints *aPoints = vtkPoints::New();
   vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
   aPoints->SetNumberOfPoints(iEnd);
@@ -55,90 +50,81 @@ static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSe
 
 vtkStandardNewMacro(SVTK_Actor);
 
-SVTK_Actor::SVTK_Actor()
+SVTK_Actor
+::SVTK_Actor():
+  myUnstructuredGrid(vtkUnstructuredGrid::New())
 {
-  myRenderer = NULL;
-  myIsInfinite = true;
+  myIsShaded = true;
 
   Visibility = Pickable = false;
 
-  myUnstructuredGrid = vtkUnstructuredGrid::New();
+  myUnstructuredGrid->Delete();
   myUnstructuredGrid->Allocate();
+}
 
-  myIsShrunk = false;
-  myIsShrinkable = true;
-  myShrinkFilter = vtkShrinkFilter::New();
+//----------------------------------------------------------------------------
+void
+SVTK_Actor
+::Initialize()
+{
+  SetInput(GetSource());
+}
 
-  myMapper = vtkDataSetMapper::New();
 
-  myMapper->SetInput(myUnstructuredGrid);
-  Superclass::InitPipeLine(myMapper);
+//----------------------------------------------------------------------------
+void
+SVTK_Actor
+::SetSource(vtkUnstructuredGrid* theUnstructuredGrid)
+{
+  if(GetSource() == theUnstructuredGrid)
+    return;
 
-  SetResolveCoincidentTopology(false);
-}
+  myUnstructuredGrid = theUnstructuredGrid;
 
-void SVTK_Actor::SetShrinkFactor(float theValue){
-  myShrinkFilter->SetShrinkFactor(theValue);
-  Modified();
+  SetInput(theUnstructuredGrid);
 }
 
-void SVTK_Actor::SetShrink()
+vtkUnstructuredGrid*
+SVTK_Actor
+::GetSource()
 {
-  if ( !myIsShrinkable ) return;
-  if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
-  {
-    myShrinkFilter->SetInput( aDataSet );
-    myPassFilter[1]->SetInput( myShrinkFilter->GetOutput() );
-    myIsShrunk = true;
-  }
+  return myUnstructuredGrid.GetPointer();
 }
 
-void SVTK_Actor::UnShrink()
+
+//----------------------------------------------------------------------------
+SVTK_Actor
+::~SVTK_Actor()
 {
-  if ( !myIsShrunk ) return;
-  if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
-  {
-    myPassFilter[1]->SetInput( aDataSet );
-    myPassFilter[1]->Modified();
-    myIsShrunk = false;
-    Modified();
-  }
 }
 
 
 //----------------------------------------------------------------------------
-SVTK_Actor::~SVTK_Actor()
+const TColStd_IndexedMapOfInteger&
+SVTK_Actor
+::GetMapIndex() const
 {
-  //if(MYDEBUG) INFOS("VTKViewer_Actor::~VTKViewer_Actor()");
-
-  myMapper->RemoveAllInputs();
-  myMapper->Delete();
-
-  myShrinkFilter->UnRegisterAllOutputs();
-  myShrinkFilter->Delete();
-
-  myUnstructuredGrid->Delete();
+  return myMapIndex;
 }
 
 
 //----------------------------------------------------------------------------
-void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
-                              const TColStd_IndexedMapOfInteger& theMapIndex)
+void
+SVTK_Actor
+::MapCells(SALOME_Actor* theMapActor,
+          const TColStd_IndexedMapOfInteger& theMapIndex)
 {
-  myUnstructuredGrid->Reset();
+  myUnstructuredGrid->Initialize();
+  myUnstructuredGrid->Allocate();
 
   vtkDataSet *aSourceDataSet = theMapActor->GetInput();
-  CopyPoints(myUnstructuredGrid,aSourceDataSet);
+  CopyPoints(GetSource(),aSourceDataSet);
 
   int aNbOfParts = theMapIndex.Extent();
   for(int ind = 1; ind <= aNbOfParts; ind++){
     int aPartId = theMapIndex( ind );
-    vtkCell* aCell = theMapActor->GetElemCell(aPartId);
-    myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
-    //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){
-    //  vtkCell* anEdgeCell = aCell->GetEdge(i);
-    //  myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
-    //}
+    if(vtkCell* aCell = theMapActor->GetElemCell(aPartId))
+      myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
   }
 
   UnShrink();
@@ -146,76 +132,69 @@ void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
     SetShrinkFactor(theMapActor->GetShrinkFactor());
     SetShrink();
   }
+
+  myMapIndex = theMapIndex;
 }
 
 
 //----------------------------------------------------------------------------
-void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor,
-                               const TColStd_IndexedMapOfInteger& theMapIndex)
+void 
+SVTK_Actor
+::MapPoints(SALOME_Actor* theMapActor,
+           const TColStd_IndexedMapOfInteger& theMapIndex)
 {
-  myUnstructuredGrid->Reset();
+  myUnstructuredGrid->Initialize();
+  myUnstructuredGrid->Allocate();
+
   if(int aNbOfParts = theMapIndex.Extent()){
     vtkPoints *aPoints = vtkPoints::New();
     aPoints->SetNumberOfPoints(aNbOfParts);
     for(int i = 0; i < aNbOfParts; i++){
       int aPartId = theMapIndex( i+1 );
-      float* aCoord = theMapActor->GetNodeCoord(aPartId);
-      aPoints->SetPoint(i,aCoord);
-      myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
+      if(float* aCoord = theMapActor->GetNodeCoord(aPartId)){
+       aPoints->SetPoint(i,aCoord);
+       myUnstructuredGrid->InsertNextCell(VTK_VERTEX,1,&i);
+      }
     }
     myUnstructuredGrid->SetPoints(aPoints);
     aPoints->Delete();
   }
 
   UnShrink();
+
+  myMapIndex = theMapIndex;
 }
 
 
 //----------------------------------------------------------------------------
-void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor,
-                             const TColStd_IndexedMapOfInteger& theMapIndex)
+void
+SVTK_Actor
+::MapEdge(SALOME_Actor* theMapActor,
+         const TColStd_IndexedMapOfInteger& theMapIndex)
 {
-  myUnstructuredGrid->Reset();
+  myUnstructuredGrid->Initialize();
+  myUnstructuredGrid->Allocate();
 
   vtkDataSet *aSourceDataSet = theMapActor->GetInput();
-  CopyPoints(myUnstructuredGrid,aSourceDataSet);
-
-  int iEnd = theMapIndex.Extent();
-  int aCellId = -1, aCellCounter = 0;
-  for(int i = 1; i <= iEnd; i++){
-    int anId = theMapIndex( i );
-    if(anId > 0) {
-      aCellCounter++;
-      aCellId = anId;
-    }
-  }
-
-  if(aCellCounter == 1){
-    vtkCell* aCell = theMapActor->GetElemCell(aCellId);
-    if(aCell->GetCellType() <= VTK_LINE){
-      myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
-    }else{
-      int aNbOfParts = aCell->GetNumberOfEdges();
-      for(int i = 1; i <= iEnd; i++){
-        int aPartId = theMapIndex(i);
-       if( aPartId < 0){
-          aPartId = -aPartId-1;
-         if(0 > aPartId || aPartId >= aNbOfParts) break;
-         vtkCell* anEdgeCell = aCell->GetEdge(aPartId);
-         myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
+  CopyPoints(GetSource(),aSourceDataSet);
+
+
+  if(theMapIndex.Extent() == 2){
+    int anEdgeId = theMapIndex(1) < 0 ? theMapIndex(1) : theMapIndex(2);
+    int aCellId = theMapIndex(1) < 0 ? theMapIndex(2) : theMapIndex(1);
+
+    if(aCellId > 0){
+      if(vtkCell* aCell = theMapActor->GetElemCell(aCellId)){
+       if(anEdgeId < 0){
+         anEdgeId = -anEdgeId - 1;
+         int aNbOfEdges = aCell->GetNumberOfEdges();
+         if(0 <= anEdgeId || anEdgeId < aNbOfEdges){
+           if(vtkCell* anEdge = aCell->GetEdge(anEdgeId))
+             myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdge->GetPointIds());
+         }
        }
       }
     }
-  }else{
-    int aNbOfParts = aSourceDataSet->GetNumberOfCells();
-    for(int i = 1; i <= iEnd; i++){
-      int aPartId = theMapIndex( i );
-      if(aPartId > 0){
-       if(aPartId >= aNbOfParts) break;
-       vtkCell* aCell = aSourceDataSet->GetCell(aPartId);
-       myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
-      }
-    }
   }
 
   UnShrink();
@@ -223,6 +202,8 @@ void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor,
     SetShrinkFactor(theMapActor->GetShrinkFactor());
     SetShrink();
   }
+
+  myMapIndex = theMapIndex;
 }
 
 //----------------------------------------------------------------------------
index 7a9b4a641f03b0a0a73415ab2806193f03e1f60b..9d1dcb224c3fb62b7ef8107722ff0ddcfa3705bb 100644 (file)
@@ -28,41 +28,58 @@ class vtkDataSetMapper;
 class vtkUnstructuredGrid;
 
 #include "SVTK.h"
-#include "SALOME_Actor.h"
+#include "SVTK_DeviceActor.h"
 
-class SVTK_EXPORT SVTK_Actor : public SALOME_Actor
+#include <vtkSmartPointer.h>
+
+class SALOME_Actor;
+
+//! This class used for internal SVTK package purpose (highlight and prehighlight)
+class SVTK_EXPORT SVTK_Actor : public SVTK_DeviceActor
 {
 public:
-  virtual ~SVTK_Actor();
-
   static SVTK_Actor* New();
 
-  vtkTypeMacro(SVTK_Actor,SALOME_Actor);
+  vtkTypeMacro(SVTK_Actor,SVTK_DeviceActor);
 
-  void  SetShrinkFactor(float value);
-  virtual void SetShrink(); 
-  virtual void UnShrink(); 
+  //! Initialiaze the instance completely
+  void
+  Initialize();
 
-  void MapCells(SALOME_Actor* theMapActor, 
-               const TColStd_IndexedMapOfInteger& theMapIndex);
+  //! Allows to set an external source 
+  void
+  SetSource(vtkUnstructuredGrid* theUnstructuredGrid);
 
-  void MapPoints(SALOME_Actor* theMapActor, 
-                const TColStd_IndexedMapOfInteger& theMapIndex);
+  //! Get its internal data set
+  vtkUnstructuredGrid*
+  GetSource();
 
-  void MapEdge(SALOME_Actor* theMapActor, 
-              const TColStd_IndexedMapOfInteger& theMapIndex);
+  //! Allow to recostruct selected cells from source SALOME_Actor and map of subindexes
+  void
+  MapCells(SALOME_Actor* theMapActor, 
+          const TColStd_IndexedMapOfInteger& theMapIndex);
 
- protected:
-  vtkUnstructuredGrid* myUnstructuredGrid;
-  vtkDataSetMapper* myMapper;
+  //! Allow to recostruct selected points from source SALOME_Actor and map of subindexes
+  void 
+  MapPoints(SALOME_Actor* theMapActor, 
+           const TColStd_IndexedMapOfInteger& theMapIndex);
 
-  vtkRenderer* myRenderer;
+  //! Allow to recostruct selected edges from source SALOME_Actor and map of subindexes
+  void 
+  MapEdge(SALOME_Actor* theMapActor, 
+         const TColStd_IndexedMapOfInteger& theMapIndex);
+
+  const TColStd_IndexedMapOfInteger&
+  GetMapIndex() const;
+
+ protected:
+  TColStd_IndexedMapOfInteger myMapIndex;
 
-  vtkShrinkFilter* myShrinkFilter;
-  bool myIsShrinkable;
-  bool myIsShrunk;
+  vtkSmartPointer<vtkUnstructuredGrid> myUnstructuredGrid;
 
   SVTK_Actor();
+  virtual
+  ~SVTK_Actor();
 };
 
 #endif
diff --git a/src/SVTK/SVTK_CubeAxesDlg.cxx b/src/SVTK/SVTK_CubeAxesDlg.cxx
new file mode 100644 (file)
index 0000000..daed684
--- /dev/null
@@ -0,0 +1,572 @@
+//  VISU VISUGUI : GUI for SMESH component
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  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
+//
+//
+//
+//  File   : SVTK_CubeAxesDlg.cxx
+//  Author : Sergey LITONIN
+//  Module : VISU
+
+#include "SVTK_CubeAxesDlg.h"
+
+#include "SVTK_MainWindow.h"
+#include "SVTK_FontWidget.h"
+
+#include "SVTK_CubeAxesActor2D.h"
+
+#include "QtxAction.h"
+
+#include <qlayout.h>
+#include <qframe.h>
+#include <qpushbutton.h>
+#include <qtabwidget.h>
+#include <qcheckbox.h>
+#include <qgroupbox.h>
+#include <qlineedit.h>
+#include <qlabel.h>
+#include <qobjectlist.h>
+#include <qvalidator.h>
+
+#include <vtkAxisActor2D.h>
+#include <vtkTextProperty.h>
+
+/*!
+ * Class       : AxisWg
+ * Description : Tab of dialog
+ */
+
+//=======================================================================
+// name    : SVTK_AxisWidget::AxisWg
+// Purpose : Constructor
+//=======================================================================
+SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
+:  QFrame(theParent)
+{
+  QValueList< QLabel* > aLabels;
+
+  // "Name" grp
+
+  myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this);
+  myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp);
+
+  QHBox* aHBox = new QHBox(myNameGrp);
+  aHBox->setSpacing(5);
+  QLabel* aLabel = new QLabel(tr("NAME"), aHBox);
+  myAxisName = new QLineEdit(aHBox);
+  aLabels.append(aLabel);
+
+  aHBox = new QHBox(myNameGrp);
+  aHBox->setSpacing(5);
+  aLabel = new QLabel(tr("FONT"), aHBox);
+  myNameFont = new SVTK_FontWidget(aHBox);
+  aLabels.append(aLabel);
+
+
+  // "Labels" grp
+
+  myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this);
+  myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp);
+
+  aHBox = new QHBox(myLabelsGrp);
+  aHBox->setSpacing(5);
+  aLabel = new QLabel(tr("NUMBER"), aHBox);
+  myLabelNumber = new QLineEdit(aHBox);
+  myLabelNumber->setValidator(new QIntValidator(0, 25, this));
+  myLabelNumber->installEventFilter(this);
+  aLabels.append(aLabel);
+
+  aHBox = new QHBox(myLabelsGrp);
+  aHBox->setSpacing(5);
+  aLabel = new QLabel(tr("OFFSET"), aHBox);
+  myLabelOffset = new QLineEdit(aHBox);
+  aLabels.append(aLabel);
+
+  aHBox = new QHBox(myLabelsGrp);
+  aHBox->setSpacing(5);
+  aLabel = new QLabel(tr("FONT"), aHBox);
+  myLabelsFont = new SVTK_FontWidget(aHBox);
+  aLabels.append(aLabel);
+
+  // "Tick marks" grp
+
+  myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this);
+  myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp);
+
+  aHBox = new QHBox(myTicksGrp);
+  aHBox->setSpacing(5);
+  aLabel = new QLabel(tr("LENGTH"), aHBox);
+  myTickLength = new QLineEdit(aHBox);
+  aLabels.append(aLabel);
+
+  // Layout
+
+  QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5);
+  aLay->addWidget(myNameGrp);
+  aLay->addWidget(myLabelsGrp);
+  aLay->addWidget(myTicksGrp);
+
+  // init
+  myIsNameVisible->setChecked(true);
+  myIsLabelsVisible->setChecked(true);
+  myIsTicksVisible->setChecked(true);
+  updateControlState();
+
+  // Adjust label widths
+  QValueList< QLabel* >::iterator anIter;
+  int aMaxWidth = 0;
+  for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
+    aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width());
+  for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
+    (*anIter)->setFixedWidth(aMaxWidth);
+
+  // connect signals and slots
+  connect(myIsNameVisible, SIGNAL(stateChanged(int)), SLOT(onNameChecked()));
+  connect(myIsLabelsVisible, SIGNAL(stateChanged(int)), SLOT(onLabelsChecked()));
+  connect(myIsTicksVisible, SIGNAL(stateChanged(int)), SLOT(onTicksChecked()));
+}
+
+SVTK_AxisWidget::~SVTK_AxisWidget()
+{
+}
+
+void SVTK_AxisWidget::updateControlState()
+{
+  onNameChecked();
+  onLabelsChecked();
+  onTicksChecked();
+}
+
+bool SVTK_AxisWidget::eventFilter(QObject* o, QEvent* e)
+{
+  if (e->type() == QEvent::FocusOut) {
+    bool isOK = false;
+    int k = myLabelNumber->text().toInt(&isOK);
+    if (isOK && k > 25) myLabelNumber->setText("25");
+  }
+  return false;
+}
+
+//=======================================================================
+// name    : SVTK_AxisWidget::onNameChecked
+// Purpose :
+//=======================================================================
+void SVTK_AxisWidget::setEnabled(QGroupBox* theGrp, const bool theState)
+{
+  QObjectList aChildren(*theGrp->children());
+  QObject* anObj;
+  for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
+    if (anObj !=0 && anObj->inherits("QHBox"))
+      ((QHBox*)anObj)->setEnabled(theState);
+}
+
+//=======================================================================
+// Labels    : SVTK_AxisWidget::onLabelsChecked
+// Purpose :
+//=======================================================================
+void SVTK_AxisWidget::onLabelsChecked()
+{
+  setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked());
+}
+
+//=======================================================================
+// Labels    : SVTK_AxisWidget::onTicksChecked
+// Purpose :
+//=======================================================================
+void SVTK_AxisWidget::onTicksChecked()
+{
+  setEnabled(myTicksGrp, myIsTicksVisible->isChecked());
+}
+
+//=======================================================================
+// name    : SVTK_AxisWidget::onNameChecked
+// Purpose :
+//=======================================================================
+void SVTK_AxisWidget::onNameChecked()
+{
+  setEnabled(myNameGrp, myIsNameVisible->isChecked());
+}
+
+//=======================================================================
+// name    : SVTK_AxisWidget::UseName
+// Purpose :
+//=======================================================================
+void SVTK_AxisWidget::UseName(const bool toUse)
+{
+  myIsNameVisible->setChecked(toUse);
+}
+
+//=======================================================================
+// name    : SVTK_AxisWidget::SetName
+// Purpose :
+//================================================== =====================
+void SVTK_AxisWidget::SetName(const QString& theName)
+{
+  myAxisName->setText(theName);
+}
+
+//=======================================================================
+// name    : SVTK_AxisWidget::SetNameFont
+// Purpose :
+//=======================================================================
+void SVTK_AxisWidget::SetNameFont(const QColor& theColor,
+                                  const int theFont,
+                                  const bool theIsBold,
+                                  const bool theIsItalic,
+                                  const bool theIsShadow)
+{
+  myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
+}
+
+//=======================================================================
+// name    : SVTK_AxisWidget::SetNameFont
+// Purpose :
+//=======================================================================
+bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
+{
+  if (theActor == 0)
+    return false;
+
+  // Name
+
+  bool useName = theActor->GetTitleVisibility();
+  QString aTitle(theActor->GetTitle());
+
+  QColor aTitleColor(255, 255, 255);
+  int aTitleFontFamily = VTK_ARIAL;
+  bool isTitleBold = false;
+  bool isTitleItalic = false;
+  bool isTitleShadow = false;
+
+  vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
+  if (aTitleProp !=0)
+  {
+    float c[ 3 ];
+    aTitleProp->GetColor(c);
+    aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
+    aTitleFontFamily = aTitleProp->GetFontFamily();
+    isTitleBold = aTitleProp->GetBold() ? true : false;
+    isTitleItalic = aTitleProp->GetItalic() ? true : false;
+    isTitleShadow = aTitleProp->GetShadow() ? true : false;
+  }
+
+  myIsNameVisible->setChecked(useName);
+  myAxisName->setText(aTitle);
+  myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
+
+  // Labels
+
+  bool useLabels = theActor->GetLabelVisibility();
+  int nbLabels = theActor->GetNumberOfLabels();
+  int anOffset = theActor->GetTickOffset();
+
+  QColor aLabelsColor(255, 255, 255);
+  int aLabelsFontFamily = VTK_ARIAL;
+  bool isLabelsBold = false;
+  bool isLabelsItalic = false;
+  bool isLabelsShadow = false;
+
+  vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
+  if (aLabelsProp !=0)
+  {
+    float c[ 3 ];
+    aLabelsProp->GetColor(c);
+    aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
+    aLabelsFontFamily = aLabelsProp->GetFontFamily();
+    isLabelsBold = aLabelsProp->GetBold() ? true : false;
+    isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
+    isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
+  }
+
+  myIsLabelsVisible->setChecked(useLabels);
+  myLabelNumber->setText(QString("%1").arg(nbLabels));
+  myLabelOffset->setText(QString("%1").arg(anOffset));
+  myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
+
+  // Tick marks
+  bool useTickMarks = theActor->GetTickVisibility();
+  int aTickLength = theActor->GetTickLength();
+
+  myIsTicksVisible->setChecked(useTickMarks);
+  myTickLength->setText(QString("%1").arg(aTickLength));
+
+  return true;
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::Apply
+// Purpose :
+//=======================================================================
+bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
+{
+   if (theActor == 0)
+    return false;
+
+  // Name
+
+  theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0);
+  theActor->SetTitle(myAxisName->text().latin1());
+
+  QColor aTitleColor(255, 255, 255);
+  int aTitleFontFamily = VTK_ARIAL;
+  bool isTitleBold = false;
+  bool isTitleItalic = false;
+  bool isTitleShadow = false;
+
+  myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
+  vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
+  if (aTitleProp)
+  {
+    aTitleProp->SetColor(aTitleColor.red() / 255.,
+                          aTitleColor.green() / 255.,
+                          aTitleColor.blue() / 255.);
+    aTitleProp->SetFontFamily(aTitleFontFamily);
+
+    aTitleProp->SetBold(isTitleBold ? 1 : 0);
+    aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
+    aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
+
+    theActor->SetTitleTextProperty(aTitleProp);
+  }
+
+  // Labels
+
+  theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0);
+
+  bool isOk = false;
+  int nbLabels = myLabelNumber->text().toInt(&isOk);
+  if (isOk)
+    theActor->SetNumberOfLabels(nbLabels);
+
+  int anOffset = myLabelOffset->text().toInt(&isOk);
+  if (isOk)
+    theActor->SetTickOffset(anOffset);
+
+  QColor aLabelsColor(255, 255, 255);
+  int aLabelsFontFamily = VTK_ARIAL;
+  bool isLabelsBold = false;
+  bool isLabelsItalic = false;
+  bool isLabelsShadow = false;
+
+  myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
+  vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
+  if (aLabelsProp)
+  {
+    aLabelsProp->SetColor(aLabelsColor.red() / 255.,
+                          aLabelsColor.green() / 255.,
+                          aLabelsColor.blue() / 255.);
+    aLabelsProp->SetFontFamily(aLabelsFontFamily);
+
+    aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
+    aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
+    aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
+
+    aLabelsProp->Modified();
+    theActor->SetLabelTextProperty(aLabelsProp);
+  }
+
+
+  // Tick marks
+  theActor->SetTickVisibility(myIsTicksVisible->isChecked());
+  int aTickLength = myTickLength->text().toInt(&isOk);
+  if (isOk)
+    theActor->SetTickLength(aTickLength);
+
+  return true;
+}
+
+/*
+  Class       : SVTK_CubeAxesDlg
+  Description : Dialog for specifynig cube axes properties
+*/
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::SVTK_CubeAxesDlg
+// Purpose : Constructor
+//=======================================================================
+SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(SVTK_MainWindow* theParent,
+                                  const char* theName,
+                                  QtxAction* theAction):
+  QDialog(theParent, 
+         theName, 
+         false,
+         WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+  myMainWindow(theParent),
+  myAction(theAction)
+{
+  setCaption(tr("CAPTION"));
+
+  QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5);
+  aLay->addWidget(createMainFrame(this));
+  aLay->addWidget(createButtonFrame(this));
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::createMainFrame
+// Purpose : Create frame containing dialog's input fields
+//=======================================================================
+QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent)
+{
+  QFrame* aFrame = new QFrame(theParent);
+
+  myTabWg = new QTabWidget(aFrame);
+
+  myAxes[ 0 ] = new SVTK_AxisWidget(myTabWg);
+  myAxes[ 1 ] = new SVTK_AxisWidget(myTabWg);
+  myAxes[ 2 ] = new SVTK_AxisWidget(myTabWg);
+
+  myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
+  myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
+  myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
+
+  myTabWg->setMargin(5);
+
+  myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
+
+  QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5);
+  aLay->addWidget(myTabWg);
+  aLay->addWidget(myIsVisible);
+
+  return aFrame;
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::createButtonFrame
+// Purpose : Create frame containing buttons
+//=======================================================================
+QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent)
+{
+  QFrame* aFrame = new QFrame(theParent);
+  aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
+
+  myOkBtn    = new QPushButton(tr("BUT_OK"), aFrame);
+  myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
+  myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
+
+  QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
+
+  QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5);
+
+  aLay->addWidget(myOkBtn);
+  aLay->addWidget(myApplyBtn);
+  aLay->addItem(aSpacer);
+  aLay->addWidget(myCloseBtn);
+
+  connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
+  connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
+  connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
+
+  return aFrame;
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg
+// Purpose : Destructor
+//=======================================================================
+SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
+{
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::Update
+// Purpose : Update dialog fields, connect signals and slots, show dialog
+//=======================================================================
+void SVTK_CubeAxesDlg::Update()
+{
+  myActor = myMainWindow->GetCubeAxes();
+
+  myAxes[ 0 ]->ReadData(myActor->GetXAxisActor2D());
+  myAxes[ 1 ]->ReadData(myActor->GetYAxisActor2D());
+  myAxes[ 2 ]->ReadData(myActor->GetZAxisActor2D());
+
+  myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::isValid
+// Purpose : Verify validity of entry data
+//=======================================================================
+bool SVTK_CubeAxesDlg::isValid() const
+{
+  return true;
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::onApply
+// Purpose : Verify validity of entry data
+//=======================================================================
+bool SVTK_CubeAxesDlg::onApply()
+{
+  bool isOk = true;
+
+  try
+  {
+    isOk = isOk && myAxes[ 0 ]->Apply(myActor->GetXAxisActor2D());
+    isOk = isOk && myAxes[ 1 ]->Apply(myActor->GetYAxisActor2D());
+    isOk = isOk && myAxes[ 2 ]->Apply(myActor->GetZAxisActor2D());
+
+
+    //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text());
+    //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text());
+    //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text());
+
+    //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels());
+    if (myIsVisible->isChecked())
+      myActor->VisibilityOn();
+    else
+      myActor->VisibilityOff();
+
+    if (isOk)
+      myMainWindow->Repaint();
+  }
+  catch(...)
+  {
+    isOk = false;
+  }
+
+  return isOk;
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::onOk
+// Purpose : SLOT called when "Ok" button pressed.
+//=======================================================================
+void SVTK_CubeAxesDlg::onOk()
+{
+  if (onApply())
+    onClose();
+}
+
+//=======================================================================
+// name    : SVTK_CubeAxesDlg::onClose
+// Purpose : SLOT called when "Close" button pressed. Close dialog
+//=======================================================================
+void SVTK_CubeAxesDlg::onClose()
+{
+  reject();
+
+  myAction->setOn( false );
+}
+
+void SVTK_CubeAxesDlg::done( int r )
+{
+  myAction->setOn( false );
+  QDialog::done( r );
+}
diff --git a/src/SVTK/SVTK_CubeAxesDlg.h b/src/SVTK/SVTK_CubeAxesDlg.h
new file mode 100644 (file)
index 0000000..bd7e525
--- /dev/null
@@ -0,0 +1,144 @@
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  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
+//
+//
+//
+//  File   : SVTK_CubeAxesDlg.h
+//  Author : Sergey LITONIN
+//  Module : VISU
+
+
+#ifndef SVTK_CubeAxesDlg_H
+#define SVTK_CubeAxesDlg_H
+
+#include <qdialog.h>
+#include <qframe.h>
+
+class QWidget;
+class QFrame;
+class QPushButton;
+class QTabWidget;
+class QCheckBox;
+class QLineEdit;
+class QGroupBox;
+
+class QtxAction;
+
+class vtkAxisActor2D;
+class SVTK_CubeAxesActor2D;
+
+class SVTK_FontWidget;
+class SVTK_AxisWidget;
+class SVTK_MainWindow;
+
+/*!
+ * Class       : SVTK_CubeAxesDlg
+ * Description : Dialog for specifynig cube axes properties
+ */
+class SVTK_CubeAxesDlg : public QDialog
+{
+  Q_OBJECT
+
+public:
+                  SVTK_CubeAxesDlg(SVTK_MainWindow* theParent,
+                                  const char* theName,
+                                  QtxAction* theAction);
+  virtual         ~SVTK_CubeAxesDlg();
+
+  void            Update();
+
+private slots:
+  void            onOk();
+  bool            onApply();
+  void            onClose();
+
+  virtual void    done( int );
+
+private:
+  QWidget*        createButtonFrame( QWidget* );
+  QWidget*        createMainFrame  ( QWidget* );
+  bool            isValid() const;
+
+private:
+  SVTK_MainWindow *myMainWindow;
+  SVTK_CubeAxesActor2D* myActor;
+  QtxAction* myAction;
+
+  QTabWidget*     myTabWg;
+  QCheckBox*      myIsVisible;
+
+  QPushButton*    myOkBtn;
+  QPushButton*    myApplyBtn;
+  QPushButton*    myCloseBtn;
+  SVTK_AxisWidget* myAxes[ 3 ];
+};
+
+/*!
+ * Class       : SVTK_AxisWidget
+ * Description : Tab of dialog
+ */
+class SVTK_AxisWidget : public QFrame
+{
+  Q_OBJECT
+
+public:
+                  SVTK_AxisWidget( QWidget* );
+                  ~SVTK_AxisWidget();
+
+  void            UseName( const bool );
+  void            SetName( const QString& );
+  void            SetNameFont( const QColor&, const int, const bool, const bool, const bool );
+  bool            ReadData( vtkAxisActor2D* );
+  bool            Apply( vtkAxisActor2D* );
+
+protected:
+  bool            eventFilter(QObject*, QEvent*);
+
+private slots:
+  void            onNameChecked();
+  void            onLabelsChecked();
+  void            onTicksChecked();
+
+private:
+  void            updateControlState();
+  void            setEnabled( QGroupBox*, const bool );
+
+private:
+  // name
+  QGroupBox*      myNameGrp;
+  QCheckBox*      myIsNameVisible;
+  QLineEdit*      myAxisName;
+  SVTK_FontWidget* myNameFont;
+
+  // labels
+  QGroupBox*      myLabelsGrp;
+  QCheckBox*      myIsLabelsVisible;
+  QLineEdit*      myLabelNumber;
+  QLineEdit*      myLabelOffset;
+  SVTK_FontWidget* myLabelsFont;
+
+  // tick marks
+  QGroupBox*      myTicksGrp;
+  QCheckBox*      myIsTicksVisible;
+  QLineEdit*      myTickLength;
+
+  friend class SVTK_CubeAxesDlg;
+};
+
+#endif
diff --git a/src/SVTK/SVTK_DeviceActor.cxx b/src/SVTK/SVTK_DeviceActor.cxx
new file mode 100644 (file)
index 0000000..be95911
--- /dev/null
@@ -0,0 +1,419 @@
+//  SVTK OBJECT : interactive object for SVTK visualization
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SVTK_DeviceActor.cxx
+//  Author : 
+//  Module : 
+//  $Header$
+
+
+#include "SVTK_DeviceActor.h"
+
+#include "VTKViewer_Transform.h"
+#include "VTKViewer_TransformFilter.h"
+#include "VTKViewer_PassThroughFilter.h"
+#include "VTKViewer_GeometryFilter.h"
+
+// VTK Includes
+#include <vtkObjectFactory.h>
+#include <vtkShrinkFilter.h>
+
+#include <vtkPolyData.h>
+#include <vtkUnstructuredGrid.h>
+
+#include <vtkPolyDataMapper.h>
+#include <vtkDataSetMapper.h>
+
+using namespace std;
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(SVTK_DeviceActor);
+
+
+//----------------------------------------------------------------------------
+SVTK_DeviceActor
+::SVTK_DeviceActor()
+{
+  myIsShrunk = false;
+  myIsShrinkable = true;
+
+  myIsShaded = true;
+  myProperty = vtkProperty::New();
+  myRepresentation = SVTK::Representation::Surface;
+
+  myIsResolveCoincidentTopology = false;
+  vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
+                                                                myPolygonOffsetUnits);
+
+  myMapper = vtkDataSetMapper::New();
+
+  myShrinkFilter = vtkShrinkFilter::New();
+
+  myGeomFilter = VTKViewer_GeometryFilter::New();
+
+  myTransformFilter = VTKViewer_TransformFilter::New();
+
+  for(int i = 0; i < 6; i++)
+    myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
+}
+
+
+//----------------------------------------------------------------------------
+SVTK_DeviceActor
+::~SVTK_DeviceActor()
+{
+  myMapper->Delete();
+
+  myProperty->Delete();
+
+  myGeomFilter->Delete();
+
+  myTransformFilter->Delete();
+
+  myShrinkFilter->Delete();
+
+  for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
+    myPassFilter[i]->Delete();
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_DeviceActor
+::SetMapper(vtkMapper* theMapper)
+{
+  InitPipeLine(theMapper);
+}
+
+void
+SVTK_DeviceActor
+::InitPipeLine(vtkMapper* theMapper)
+{
+  if(theMapper){
+    int anId = 0;
+    myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
+    myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
+    
+    anId++; // 1
+    myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
+
+    anId++; // 2
+    myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); 
+    myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
+
+    anId++; // 3
+    myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
+
+    anId++; // 4
+    myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
+    myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
+
+    anId++; // 5
+    if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
+      aMapper->SetInput(myPassFilter[anId]->GetOutput());
+    }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
+      aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
+    }
+  }else
+    myPassFilter[ 0 ]->SetInput( NULL );
+  Superclass::SetMapper(theMapper);
+}
+
+//----------------------------------------------------------------------------
+vtkDataSet* 
+SVTK_DeviceActor
+::GetInput()
+{
+  return myPassFilter.front()->GetOutput();
+}
+
+void
+SVTK_DeviceActor
+::SetInput(vtkDataSet* theDataSet)
+{
+  myMapper->SetInput(theDataSet);
+  InitPipeLine(myMapper);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_DeviceActor::
+SetStoreMapping(bool theStoreMapping)
+{
+  myGeomFilter->SetStoreMapping(theStoreMapping);
+}
+
+
+
+//----------------------------------------------------------------------------
+unsigned long int 
+SVTK_DeviceActor
+::GetMTime()
+{
+  unsigned long mTime = this->Superclass::GetMTime();
+
+  mTime = max(mTime,myGeomFilter->GetMTime());
+
+  mTime = max(mTime,myTransformFilter->GetMTime());
+
+  if(myIsShrunk)
+    mTime = max(mTime,myShrinkFilter->GetMTime());
+
+  for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
+    max(mTime,myPassFilter[i]->GetMTime());
+
+  return mTime;
+}
+
+
+//----------------------------------------------------------------------------
+void 
+SVTK_DeviceActor
+::SetTransform(VTKViewer_Transform* theTransform)
+{
+  myTransformFilter->SetTransform(theTransform);
+}
+
+
+//----------------------------------------------------------------------------
+bool
+SVTK_DeviceActor
+::IsShrunkable() 
+{ 
+  return myIsShrinkable;
+}
+  
+void
+SVTK_DeviceActor
+::SetShrinkable(bool theIsShrinkable) 
+{ 
+  myIsShrinkable = theIsShrinkable;
+}
+  
+bool
+SVTK_DeviceActor
+::IsShrunk() 
+{ 
+  return myIsShrunk;
+}
+
+void
+SVTK_DeviceActor
+::SetShrink() 
+{
+  if ( !myIsShrinkable ) 
+    return;
+  if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
+  {
+    myShrinkFilter->SetInput( aDataSet );
+    myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
+    myIsShrunk = true;
+  }
+}
+
+void 
+SVTK_DeviceActor
+::UnShrink() 
+{
+  if ( !myIsShrunk ) return;
+  if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
+  {    
+    myPassFilter[ 1 ]->SetInput( aDataSet );
+    myIsShrunk = false;
+  }
+}
+
+float
+SVTK_DeviceActor
+::GetShrinkFactor()
+{
+  return myShrinkFilter->GetShrinkFactor();
+}
+
+void 
+SVTK_DeviceActor
+::SetShrinkFactor(float theValue)
+{
+  myShrinkFilter->SetShrinkFactor(theValue);
+}
+
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_DeviceActor
+::SetRepresentation(SVTK::Representation::Type theMode)
+{ 
+  using namespace SVTK::Representation;
+  if(IsShaded()){
+    switch(myRepresentation){
+    case Points : 
+    case Surface : 
+      myProperty->DeepCopy(GetProperty());
+    }
+    
+    switch(theMode){
+    case Points : 
+    case Surface : 
+      GetProperty()->DeepCopy(myProperty);
+      break;
+    default:
+      GetProperty()->SetAmbient(1.0);
+      GetProperty()->SetDiffuse(0.0);
+      GetProperty()->SetSpecular(0.0);
+    }
+  }
+
+  switch(theMode){
+  case Insideframe : 
+    myGeomFilter->SetInside(true);
+    myGeomFilter->SetWireframeMode(true);
+    GetProperty()->SetRepresentation(VTK_WIREFRAME);
+    break;
+  case Points : 
+    GetProperty()->SetPointSize(GetDefaultPointSize());  
+    GetProperty()->SetRepresentation(VTK_POINTS);
+    myGeomFilter->SetWireframeMode(false);
+    myGeomFilter->SetInside(false);
+    break;
+  case Wireframe : 
+    GetProperty()->SetRepresentation(VTK_WIREFRAME);
+    myGeomFilter->SetWireframeMode(true);
+    myGeomFilter->SetInside(false);
+    break;
+  case Surface : 
+    GetProperty()->SetRepresentation(VTK_SURFACE);
+    myGeomFilter->SetWireframeMode(false);
+    myGeomFilter->SetInside(false);
+    break;
+  }
+
+  myRepresentation = theMode;
+}
+
+SVTK::Representation::Type 
+SVTK_DeviceActor
+::GetRepresentation()
+{
+  return myRepresentation;
+}
+
+float
+SVTK_DeviceActor
+::GetDefaultPointSize()
+{
+  return 5;
+}
+
+float
+SVTK_DeviceActor
+::GetDefaultLineWidth()
+{
+  return 3;
+}
+
+
+bool
+SVTK_DeviceActor
+::IsShaded()
+{
+  return myIsShaded;
+}
+
+void
+SVTK_DeviceActor
+::SetShaded(bool theShaded)
+{
+  myIsShaded = theShaded;
+}
+
+
+//----------------------------------------------------------------------------
+int
+SVTK_DeviceActor
+::GetNodeObjId(int theVtkID)
+{
+  return theVtkID;
+}
+
+float* 
+SVTK_DeviceActor
+::GetNodeCoord(int theObjID)
+{
+  return GetInput()->GetPoint(theObjID);
+}
+
+
+vtkCell* 
+SVTK_DeviceActor
+::GetElemCell(int theObjID)
+{
+  return GetInput()->GetCell(theObjID);
+}
+
+int
+SVTK_DeviceActor
+::GetElemObjId(int theVtkID) 
+{ 
+  return theVtkID;
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_DeviceActor
+::Render(vtkRenderer *ren, vtkMapper* m)
+{
+  if(myIsResolveCoincidentTopology){
+    int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
+    float aFactor, aUnit; 
+    vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
+    
+    vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
+    vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
+                                                                  myPolygonOffsetUnits);
+    Superclass::Render(ren,m);
+    
+    vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
+    vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
+  }else{
+    Superclass::Render(ren,m);
+  }
+}
+
+
+void
+SVTK_DeviceActor
+::SetPolygonOffsetParameters(float factor, float units)
+{
+  myPolygonOffsetFactor = factor;
+  myPolygonOffsetUnits = units;
+}
+
+void
+SVTK_DeviceActor
+::GetPolygonOffsetParameters(float& factor, float& units)
+{
+  factor = myPolygonOffsetFactor;
+  units = myPolygonOffsetUnits;
+}
diff --git a/src/SVTK/SVTK_DeviceActor.h b/src/SVTK/SVTK_DeviceActor.h
new file mode 100644 (file)
index 0000000..f8a49bc
--- /dev/null
@@ -0,0 +1,209 @@
+//  SVTK OBJECT : interactive object for SVTK visualization
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SVTK_DeviceActor.h
+//  Author : 
+//  Module : 
+//  $Header$
+
+#ifndef SVTK_DEVICE_ACTOR_H
+#define SVTK_DEVICE_ACTOR_H
+
+#include <vector>
+
+#include <vtkLODActor.h>
+#include <vtkProperty.h>
+
+class VTKViewer_Transform;
+class VTKViewer_TransformFilter;
+class VTKViewer_PassThroughFilter;
+class VTKViewer_GeometryFilter;
+
+class vtkCell;
+class vtkDataSet;
+class vtkShrinkFilter;
+class vtkDataSetMapper;
+
+//----------------------------------------------------------------------------
+namespace SVTK
+{
+  namespace Representation
+  {
+    typedef int Type;
+    const Type Points = VTK_POINTS;
+    const Type Wireframe = VTK_WIREFRAME;
+    const Type Surface = VTK_SURFACE;
+    const Type Insideframe = Surface + 1;
+  }
+}
+
+
+//----------------------------------------------------------------------------
+class SVTK_DeviceActor: public vtkLODActor
+{
+ public:
+  vtkTypeMacro(SVTK_DeviceActor,vtkLODActor);
+
+  static
+  SVTK_DeviceActor* 
+  New();
+
+  //! Apply a view transformation
+  virtual
+  void
+  SetTransform(VTKViewer_Transform* theTransform); 
+
+  //! To insert some additional filters and then sets the given #vtkMapper
+  virtual
+  void
+  SetMapper(vtkMapper* theMapper); 
+
+  //! Allows to get initial #vtkDataSet
+  virtual
+  vtkDataSet* 
+  GetInput(); 
+
+  //! Allows to set initial #vtkDataSet
+  virtual
+  void
+  SetInput(vtkDataSet* theDataSet); 
+
+  /** @name For selection mapping purpose */
+  //@{
+  virtual
+  int
+  GetNodeObjId(int theVtkID);
+
+  virtual
+  float* 
+  GetNodeCoord(int theObjID);
+
+  virtual
+  int
+  GetElemObjId(int theVtkID);
+
+  virtual
+  vtkCell* 
+  GetElemCell(int theObjID);
+
+  //! To provide VTK to Object and backward mapping
+  virtual 
+  void
+  SetStoreMapping(bool theStoreMapping);
+  //@}
+
+  virtual 
+  unsigned long int 
+  GetMTime();
+
+  /** @name For shrink mamnagement purpose */
+  //@{
+  float
+  GetShrinkFactor();
+
+  virtual 
+  void  
+  SetShrinkFactor(float value);
+
+  virtual
+  void
+  SetShrinkable(bool theIsShrinkable);
+
+  bool
+  IsShrunkable();
+
+  bool
+  IsShrunk();
+
+  virtual
+  void
+  SetShrink(); 
+
+  virtual
+  void
+  UnShrink(); 
+  //@}
+
+  /** @name For representation mamnagement purpose */
+  virtual
+  void 
+  SetRepresentation(SVTK::Representation::Type theMode);
+
+  SVTK::Representation::Type 
+  GetRepresentation();
+
+  virtual
+  float
+  GetDefaultPointSize();
+
+  virtual
+  float
+  GetDefaultLineWidth();
+
+  bool
+  IsShaded();
+
+  void
+  SetShaded(bool theShaded);
+  //@}
+
+  virtual
+  void
+  Render(vtkRenderer *, vtkMapper *);
+
+ protected:
+  SVTK::Representation::Type myRepresentation;
+  vtkProperty *myProperty;
+  bool myIsShaded;
+
+  //! To initialize internal pipeline
+  void
+  InitPipeLine(vtkMapper* theMapper); 
+
+  VTKViewer_GeometryFilter *myGeomFilter;
+  VTKViewer_TransformFilter *myTransformFilter;
+  std::vector<VTKViewer_PassThroughFilter*> myPassFilter;
+  vtkShrinkFilter* myShrinkFilter;
+  vtkDataSetMapper* myMapper;
+
+  bool myIsShrinkable;
+  bool myIsShrunk;
+  
+  bool myIsResolveCoincidentTopology;
+  float myPolygonOffsetFactor;
+  float myPolygonOffsetUnits;
+
+  void SetPolygonOffsetParameters(float factor, float units);
+  void GetPolygonOffsetParameters(float& factor, float& units);
+
+  SVTK_DeviceActor();
+  ~SVTK_DeviceActor();
+
+ private:
+  SVTK_DeviceActor(const SVTK_DeviceActor&); // Not implemented
+  void operator=(const SVTK_DeviceActor&); // Not implemented
+
+};
+
+
+#endif //SVTK_DEVICE_ACTOR_H
diff --git a/src/SVTK/SVTK_Event.h b/src/SVTK/SVTK_Event.h
new file mode 100644 (file)
index 0000000..f4c1c42
--- /dev/null
@@ -0,0 +1,68 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : Alexander SLADKOV
+//  Module : SALOME
+//  $Header$
+
+#ifndef SVTK_Event_h
+#define SVTK_Event_h
+
+#include <vtkCommand.h>
+
+namespace SVTK
+{
+  enum Event 
+  {
+    SpaceMouseMoveEvent = vtkCommand::UserEvent + 1000, 
+    SpaceMouseButtonEvent,
+    PanLeftEvent,
+    PanRightEvent,
+    PanUpEvent,
+    PanDownEvent,
+    ZoomInEvent,
+    ZoomOutEvent,
+    RotateLeftEvent,
+    RotateRightEvent,
+    RotateUpEvent,
+    RotateDownEvent,
+    PlusSpeedIncrementEvent,
+    MinusSpeedIncrementEvent,
+    SetSpeedIncrementEvent,
+
+    SetSMDecreaseSpeedEvent,
+    SetSMIncreaseSpeedEvent,
+    SetSMDominantCombinedSwitchEvent,
+
+    StartZoom,
+    StartPan,
+    StartRotate,
+    StartGlobalPan,
+    StartFitArea,
+
+    LastEvent
+  };
+}
+  
+#endif
diff --git a/src/SVTK/SVTK_FontWidget.cxx b/src/SVTK/SVTK_FontWidget.cxx
new file mode 100644 (file)
index 0000000..edaa9a6
--- /dev/null
@@ -0,0 +1,149 @@
+//  VISU VISUGUI : GUI for SMESH component
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  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
+//
+//
+//
+//  File   : 
+//  Author : Sergey LITONIN
+//  Module : 
+
+#include "SVTK_FontWidget.h"
+
+#include <qtoolbutton.h>
+#include <qcombobox.h>
+#include <qcolordialog.h>
+#include <qcheckbox.h>
+
+#include <vtkTextProperty.h>
+
+/*!
+ * Class       : SVTK_FontWidget
+ * Description : Dialog for specifynig font
+ */
+
+//=======================================================================
+// name    : SVTK_FontWidget
+// Purpose : Constructor
+//=======================================================================
+SVTK_FontWidget::SVTK_FontWidget( QWidget* theParent )
+: QHBox( theParent )
+{
+  setSpacing( 5 );
+  myColorBtn = new QToolButton( this );
+  myColorBtn->setMinimumWidth( 20 );
+
+  myFamily = new QComboBox( this );
+  myFamily->insertItem( tr( "ARIAL" ) );
+  myFamily->insertItem( tr( "COURIER" ) );
+  myFamily->insertItem( tr( "TIMES" ) );
+
+  myBold = new QCheckBox( tr( "BOLD" ), this );
+  myItalic = new QCheckBox( tr( "ITALIC" ), this );
+  myShadow = new QCheckBox( tr( "SHADOW" ), this );
+
+  connect( myColorBtn, SIGNAL( clicked() ), SLOT( onColor() ) );
+}
+
+//=======================================================================
+// name    : ~SVTK_FontWidget
+// Purpose : Destructor
+//=======================================================================
+SVTK_FontWidget::~SVTK_FontWidget()
+{
+}
+
+//=======================================================================
+// name    : SetColor
+// Purpose :
+//=======================================================================
+void SVTK_FontWidget::SetColor( const QColor& theColor )
+{
+  myColorBtn->setPaletteBackgroundColor( theColor );
+}
+
+//=======================================================================
+// name    : GetColor
+// Purpose :
+//=======================================================================
+QColor SVTK_FontWidget::GetColor() const
+{
+  return myColorBtn->paletteBackgroundColor();
+}
+
+//=======================================================================
+// name    : onColor
+// Purpose :
+//=======================================================================
+void SVTK_FontWidget::onColor()
+{
+  QColor aColor = QColorDialog::getColor( GetColor(), this );
+  if ( aColor.isValid() )
+    SetColor( aColor );
+}
+
+//=======================================================================
+// name    : SetData
+// Purpose :
+//=======================================================================
+void SVTK_FontWidget::SetData( const QColor& theColor,
+                              const int theFamily,
+                              const bool theBold,
+                              const bool theItalic,
+                              const bool theShadow )
+{
+  SetColor( theColor );
+
+  if ( theFamily == VTK_ARIAL )
+    myFamily->setCurrentItem( 0 );
+  else if ( theFamily == VTK_COURIER )
+    myFamily->setCurrentItem( 1 );
+  else
+    myFamily->setCurrentItem( 2 );
+
+  myBold->setChecked( theBold );
+  myItalic->setChecked( theItalic );
+  myShadow->setChecked( theShadow );
+}
+
+//=======================================================================
+// name    : GetData
+// Purpose :
+//=======================================================================
+void SVTK_FontWidget::GetData( QColor& theColor,
+                              int& theFamily,
+                              bool& theBold,
+                              bool& theItalic,
+                              bool& theShadow ) const
+{
+  theColor = GetColor();
+
+  int anItem =myFamily->currentItem();
+  if ( anItem == 0 )
+    theFamily = VTK_ARIAL;
+  else if ( anItem == 1 )
+    theFamily = VTK_COURIER;
+  else
+    theFamily = VTK_TIMES;
+
+  theBold = myBold->isChecked();
+  theItalic = myItalic->isChecked();
+  theShadow = myShadow->isChecked();
+}
diff --git a/src/SVTK/SVTK_FontWidget.h b/src/SVTK/SVTK_FontWidget.h
new file mode 100644 (file)
index 0000000..c06e1e4
--- /dev/null
@@ -0,0 +1,68 @@
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  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
+//
+//
+//
+//  File   : 
+//  Author : Sergey LITONIN
+//  Module : 
+
+
+#ifndef SVTK_FontWidget_H
+#define SVTK_FontWidget_H
+
+#include <qhbox.h>
+
+class QToolButton;
+class QComboBox;
+class QCheckBox;
+class QColor;
+
+
+/*!
+ * Class       : SVTK_FontWidget
+ * Description : Dialog for specifynig font
+ */
+class SVTK_FontWidget : public QHBox
+{
+  Q_OBJECT
+
+public:
+                SVTK_FontWidget( QWidget* );
+  virtual       ~SVTK_FontWidget();
+
+  void          SetColor( const QColor& );
+  QColor        GetColor() const;
+
+  void          SetData( const QColor&, const int, const bool, const bool, const bool );
+
+  void          GetData( QColor&, int&, bool&, bool&, bool& ) const;
+
+private slots:
+  void          onColor();
+
+private:
+  QToolButton*  myColorBtn;
+  QComboBox*    myFamily;
+  QCheckBox*    myBold;
+  QCheckBox*    myItalic;
+  QCheckBox*    myShadow;
+};
+
+#endif
index bc7e2f72051eff12dc78e584a3c277cc513c608c..b47d26e6c8757a08fdf0e61c77a11c8c3a0c259d 100644 (file)
 
 #include "SALOME_InteractiveObject.hxx"
 
-namespace VTK
+/*!
+  \file SVTK_Functor.h
+  This file contains numbers of functors that allows user to perform corresponding operations with existing presentations.
+  Combination with algorithms it gives powerful, flexible and simple to extend way to introduce new type of operation.
+*/
+
+namespace SVTK
 {
+  using namespace VTK;
+
+  //! This functor check, if the actor have pointed entry
   template<class TActor> 
   struct TIsSameEntry
   {
     std::string myEntry;
-    TIsSameEntry(const char* theEntry): myEntry(theEntry) {}
+    //! To construct the functor
+    TIsSameEntry(const char* theEntry): 
+      myEntry(theEntry) 
+    {}
+    //! To calculate the functor
     bool operator()(TActor* theActor)
     {
       if ( theActor->hasIO() )
@@ -48,13 +61,16 @@ namespace VTK
 
 
   //----------------------------------------------------------------
+  //! This functor check, if the actor point to the same #SALOME_InteractiveObject
   template<class TActor> 
   struct TIsSameIObject
   {
     Handle(SALOME_InteractiveObject) myIObject;
+    //! To construct the functor
     TIsSameIObject(const Handle(SALOME_InteractiveObject)& theIObject):
       myIObject(theIObject)
     {}
+    //! To calculate the functor
     bool operator()(TActor* theActor)
     {
       if(theActor->hasIO())
@@ -68,11 +84,18 @@ namespace VTK
 
 
   //----------------------------------------------------------------
+  /*!
+    This highlight every input actor
+  */
   template<class TActor> 
   struct THighlight
   {
     bool myIsHighlight;
-    THighlight(bool theIsHighlight): myIsHighlight( theIsHighlight ) {}
+    //! To construct the functor
+    THighlight(bool theIsHighlight):
+      myIsHighlight( theIsHighlight ) 
+    {}
+    //! To calculate the functor
     void operator()(TActor* theActor) 
     {
       if(theActor->GetVisibility() && theActor->GetMapper())
diff --git a/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx b/src/SVTK/SVTK_GenericRenderWindowInteractor.cxx
new file mode 100644 (file)
index 0000000..e3cb3c8
--- /dev/null
@@ -0,0 +1,138 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#include "SVTK_GenericRenderWindowInteractor.h"
+#include "SVTK_Selector.h"
+
+#include <vtkObjectFactory.h>
+#include <vtkCommand.h>
+
+#include <qtimer.h>
+
+using namespace std;
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(QVTK_GenericRenderWindowInteractor);
+
+QVTK_GenericRenderWindowInteractor
+::QVTK_GenericRenderWindowInteractor()
+{
+  myTimer = new QTimer( ) ;
+  connect(myTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut())) ;
+}
+
+QVTK_GenericRenderWindowInteractor
+::~QVTK_GenericRenderWindowInteractor()
+{
+  delete myTimer;
+}
+
+
+//----------------------------------------------------------------------------
+void
+QVTK_GenericRenderWindowInteractor
+::OnTimeOut() 
+{
+  if( GetEnabled() ) {
+    this->InvokeEvent(vtkCommand::TimerEvent,NULL);
+  }
+}
+
+int
+QVTK_GenericRenderWindowInteractor
+::CreateTimer(int vtkNotUsed(timertype)) 
+{
+  //
+  // Start a one-shot timer for <DELAY> ms. 
+  //
+  static int DELAY = 1;
+  myTimer->start(DELAY,TRUE);
+  return 1;
+}
+
+int
+QVTK_GenericRenderWindowInteractor
+::DestroyTimer(void) 
+{
+  //
+  // :TRICKY: Tue May  2 00:17:32 2000 Pagey
+  //
+  // QTimer will automatically expire after 10ms. So 
+  // we do not need to do anything here. In fact, we 
+  // should not even Stop() the QTimer here because doing 
+  // this will skip some of the processing that the TimerFunc()
+  // does and will result in undesirable effects. For 
+  // example, this will result in vtkLODActor to leave
+  // the models in low-res mode after the mouse stops
+  // moving. 
+  //
+  return 1;
+}
+
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(SVTK_GenericRenderWindowInteractor);
+
+SVTK_GenericRenderWindowInteractor
+::SVTK_GenericRenderWindowInteractor():
+  myRenderWidget(NULL)
+{
+}
+
+SVTK_GenericRenderWindowInteractor
+::~SVTK_GenericRenderWindowInteractor()
+{
+}
+
+SVTK_Selector*
+SVTK_GenericRenderWindowInteractor
+::GetSelector()
+{
+  return mySelector.GetPointer();
+}
+
+void
+SVTK_GenericRenderWindowInteractor
+::SetSelector(SVTK_Selector* theSelector)
+{
+  mySelector = theSelector;
+}
+
+QWidget*
+SVTK_GenericRenderWindowInteractor
+::GetRenderWidget()
+{
+  return myRenderWidget;
+}
+
+void
+SVTK_GenericRenderWindowInteractor
+::SetRenderWidget(QWidget* theRenderWidget)
+{
+  myRenderWidget = theRenderWidget;
+}
diff --git a/src/SVTK/SVTK_GenericRenderWindowInteractor.h b/src/SVTK/SVTK_GenericRenderWindowInteractor.h
new file mode 100644 (file)
index 0000000..d15fdc5
--- /dev/null
@@ -0,0 +1,126 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#ifndef SVTK_GenericRenderWindowInteractor_h
+#define SVTK_GenericRenderWindowInteractor_h
+
+#include "SVTK.h"
+
+#include <qobject.h>
+#include <vtkGenericRenderWindowInteractor.h>
+#include <vtkSmartPointer.h>
+
+class QTimer;
+class QWidget;
+
+class SVTK_Selector;
+class SVTK_Renderer;
+
+
+//============================================================================
+//! Introduction of the class is intended to implement Qt based #CreateTimer and #DestroyTimer functionality.
+/*!
+  The class intendes to implement platform indepenedant subclass of vtkRenderWindowInteractor.
+  This is done by usage of Qt library.
+  \note
+  The Signal/Slot mechanism used by Qt requires that QObject 
+  appear as the first class when using multiple inheritance. 
+  Hence the order of the two classes QObject and vtkRenderWindowInteractor
+  matters here. So, be careful, not to change the sequence of the inheritance by accident. 
+*/
+class SVTK_EXPORT QVTK_GenericRenderWindowInteractor: 
+ public QObject,
+ public vtkGenericRenderWindowInteractor
+{
+  Q_OBJECT;
+
+ public:
+  static QVTK_GenericRenderWindowInteractor* New();
+  vtkTypeMacro(QVTK_GenericRenderWindowInteractor,vtkGenericRenderWindowInteractor);
+
+  //! Starts the QTimer instance on defined microseconds
+  virtual
+  int
+  CreateTimer( int ) ; 
+
+  //! Stops the QTimer instance
+  virtual
+  int
+  DestroyTimer() ; 
+
+ protected slots:
+  //! The slot connects to QTimer::timeout signal to invoke vtkCommand::TimerEvent
+  void
+  OnTimeOut();
+
+ protected:
+  QVTK_GenericRenderWindowInteractor(); //!< Instatiate QTimer
+  ~QVTK_GenericRenderWindowInteractor(); //!< Destroy the instance of QTimer
+
+  QTimer* myTimer; //!< Qt timer device
+};
+
+
+//============================================================================
+//! This class introduce SALOME specific to the base one
+/*!
+  In this class new members is added (#mySelector and #myRenderWidget).
+  They are used for initialization of #SVTK_InteractorStyle by redefinition of
+  #SVTK_InteractorStyle::SetInteractor method
+*/
+class SVTK_EXPORT SVTK_GenericRenderWindowInteractor: public QVTK_GenericRenderWindowInteractor
+{
+ public:
+  static SVTK_GenericRenderWindowInteractor* New();
+  vtkTypeMacro(SVTK_GenericRenderWindowInteractor,QVTK_GenericRenderWindowInteractor);
+
+  //! To get access to SVTK_Selector
+  SVTK_Selector* 
+  GetSelector(); 
+
+  //! To initialize mySelector field
+  void
+  SetSelector(SVTK_Selector* theSelector);
+
+  //! To get access to QWidget, where vtkRenderWindow maps to.
+  QWidget*
+  GetRenderWidget();
+
+  //! To initialize myRenderWidget field.
+  void
+  SetRenderWidget(QWidget* theRenderWidget);
+
+ protected:
+  SVTK_GenericRenderWindowInteractor();
+  ~SVTK_GenericRenderWindowInteractor();
+
+  vtkSmartPointer<SVTK_Selector> mySelector; //!< Keeps a pointer to SVTK_Selector
+  QWidget* myRenderWidget; //!< Keeps a pointer to QWidget, where vtkRenderWindow maps to.
+};
+
+#endif
index fa78468003f1319b3a69b661e64ec44eb9b69a26..963aa1894733d7fd039d7a8b89608e7d78c9fa16 100644 (file)
 //
 //
 //
-//  File   : SVTK_InteractorStyle.cxx
-//  Author : Christophe ATTANASIO
+//  File   : 
+//  Author : 
 //  Module : SALOME
 //  $Header$
 
 
 #include "SVTK_InteractorStyle.h"
 
-#include "VTKViewer_CellRectPicker.h"
 #include "VTKViewer_Utilities.h"
-#include "VTKViewer_RectPicker.h"
+#include "SVTK_GenericRenderWindowInteractor.h"
 
-#include "SVTK_RenderWindowInteractor.h"
-#include "SVTK_RenderWindow.h"
-#include "SVTK_ViewWindow.h"
-
-#include "SALOME_Actor.h"
-#include "SVTK_Actor.h"
+#include "SVTK_Selection.h"
+#include "SVTK_Event.h" 
 #include "SVTK_Selector.h"
+#include "SVTK_Functor.h"
 
-#include "SALOME_ListIteratorOfListIO.hxx"
-#include "SALOME_ListIO.hxx"
+#include "VTKViewer_Algorithm.h"
+#include "SVTK_Functor.h"
 
-#include "SUIT_Session.h"
-#include "CAM_Application.h"
+#include "SALOME_Actor.h"
 
 #include <vtkObjectFactory.h>
 #include <vtkMath.h>
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
 #include <vtkPicker.h>
-#include <vtkPointPicker.h>
-#include <vtkCellPicker.h>
-#include <vtkLine.h> 
-#include <vtkMapper.h>
-#include <vtkDataSet.h>
-#include <vtkSmartPointer.h>
 #include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkRendererCollection.h>
 
 #include <qapplication.h>
+#include <qpixmap.h>
 //VRV: porting on Qt 3.0.5
 #if QT_VERSION >= 0x030005
 #include <qpainter.h>
 
 using namespace std;
 
-
 namespace
 {
-  int
-  GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId)
+  inline 
+  void
+  GetEventPosition(vtkRenderWindowInteractor* theInteractor,
+                  int& theX, 
+                  int& theY)
   {
-    int anEdgeId = -1;
-    if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
-      float aPickPosition[3];
-      thePicker->GetPickPosition(aPickPosition);
-      float aMinDist = 1000000.0, aDist = 0;
-      for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
-       if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
-         int subId;  float pcoords[3], closestPoint[3], weights[3];
-         aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
-         if (aDist < aMinDist) {
-           aMinDist = aDist;
-           anEdgeId = i;
-         }
-       }
-      }
-    }
-    return anEdgeId;
+    theInteractor->GetEventPosition(theX,theY);
+    theY = theInteractor->GetSize()[1] - theY - 1;
   }
-  
 
-  
-  bool CheckDimensionId(Selection_Mode theMode, SALOME_Actor *theActor, vtkIdType theObjId){
-    switch(theMode){
-    case CellSelection:
-      return true;
-    case EdgeSelection:
-      return ( theActor->GetObjDimension( theObjId ) == 1 );
-    case FaceSelection:
-      return ( theActor->GetObjDimension( theObjId ) == 2 );
-    case VolumeSelection:
-      return ( theActor->GetObjDimension( theObjId ) == 3 );
-    };
-    return false;
+  //==================================================================
+  // function : GetFirstSALOMEActor
+  // purpose  :
+  //==================================================================
+  struct THaveIO
+  {
+    bool
+    operator()(SALOME_Actor* theActor)
+    {
+      return theActor->hasIO();
+    }
+  };
+
+  inline
+  SALOME_Actor* 
+  GetFirstSALOMEActor(vtkPicker *thePicker)
+  {
+    return VTK::Find<SALOME_Actor>(thePicker->GetActors(),THaveIO());
   }
-}  
-  
+}
+
+
 //----------------------------------------------------------------------------
 vtkStandardNewMacro(SVTK_InteractorStyle);
 //----------------------------------------------------------------------------
-
 SVTK_InteractorStyle
-::SVTK_InteractorStyle() 
+::SVTK_InteractorStyle():
+  mySelectionEvent(new SVTK_SelectionEvent()),
+  myPicker(vtkPicker::New()),
+  myLastHighlitedActor(NULL),
+  myLastPreHighlitedActor(NULL),
+  myControllerIncrement(SVTK_ControllerIncrement::New()),
+  myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New())
 {
-  myPreViewActor = NULL;
-  myInteractor = NULL;
-  myViewWindow = NULL;
-  myGUIWindow = NULL;
+  myPicker->Delete();
+
   this->MotionFactor = 10.0;
   this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
   this->RadianToDegree = 180.0 / vtkMath::Pi();
   this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
+
   loadCursors();
 
-  myPreSelectionActor = SVTK_Actor::New();
-  myPreSelectionActor->GetProperty()->SetColor(0,1,1);
-  myPreSelectionActor->GetProperty()->SetLineWidth(5);
-  myPreSelectionActor->GetProperty()->SetPointSize(5);
+  // set custom event handling function (to handle 3d space mouse events)
+  EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents );
 
-  OnSelectionModeChanged();
+  // set default values of properties.  user may edit them in preferences.
+  mySMDecreaseSpeedBtn = 1;
+  mySMIncreaseSpeedBtn = 2;
+  mySMDominantCombinedSwitchBtn = 9;
+  //
+  myControllerIncrement->Delete();
+  myControllerOnKeyDown->Delete();
 }
 
 //----------------------------------------------------------------------------
 SVTK_InteractorStyle
 ::~SVTK_InteractorStyle() 
 {
-  myViewWindow->RemoveActor(myPreSelectionActor);
 }
 
 //----------------------------------------------------------------------------
-SVTK_Selector*
+QWidget*
 SVTK_InteractorStyle
-::GetSelector() 
+::GetRenderWidget()
 {
-  return myViewWindow->GetSelector();
+  return myInteractor->GetRenderWidget();
 }
 
-//----------------------------------------------------------------------------
-void
+SVTK_Selector*
 SVTK_InteractorStyle
-::setPreselectionProp(const double& theRed, 
-                     const double& theGreen, 
-                     const double& theBlue, 
-                     const int& theWidth) 
+::GetSelector() 
 {
-  if ( myPreSelectionActor->GetProperty() == 0 )
-    return;
-  myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
-  myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
-  myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
+  return myInteractor->GetSelector();
 }
 
 //----------------------------------------------------------------------------
-void
+SVTK_SelectionEvent*
 SVTK_InteractorStyle
-::SetInteractor(vtkRenderWindowInteractor *theInteractor)
+::GetSelectionEvent()
 {
-  myInteractor = dynamic_cast<SVTK_RenderWindowInteractor*>(theInteractor);
-  Superclass::SetInteractor(theInteractor);
-}
+  mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
 
-//----------------------------------------------------------------------------
-int
-SVTK_InteractorStyle
-::GetState()
-{
-  return State | ForcedState;
-}
+  mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
+  mySelectionEvent->myIsShift = Interactor->GetShiftKey();
 
-//----------------------------------------------------------------------------
-void 
-SVTK_InteractorStyle
-::setViewWindow(SVTK_ViewWindow* theViewWindow)
-{
-  myViewWindow = theViewWindow;
-  myViewWindow->AddActor(myPreSelectionActor);
-  myPreSelectionActor->Delete();
+  mySelectionEvent->myLastX = mySelectionEvent->myX;
+  mySelectionEvent->myLastY = mySelectionEvent->myY;
+
+  GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY );
+
+  return mySelectionEvent.get();
 }
 
 //----------------------------------------------------------------------------
-void
+SVTK_SelectionEvent*
 SVTK_InteractorStyle
-::setGUIWindow(QWidget* theWindow)
+::GetSelectionEventFlipY()
 {
-  myGUIWindow = theWindow;
+  mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
+
+  mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
+  mySelectionEvent->myIsShift = Interactor->GetShiftKey();
+
+  mySelectionEvent->myLastX = mySelectionEvent->myX;
+  mySelectionEvent->myLastY = mySelectionEvent->myY;
+
+  this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
+
+  return mySelectionEvent.get();
 }
 
 //----------------------------------------------------------------------------
@@ -208,29 +193,24 @@ void
 SVTK_InteractorStyle
 ::RotateXY(int dx, int dy)
 {
-  double rxf;
-  double ryf;
-  vtkCamera *cam;
-  
-  if (this->CurrentRenderer == NULL)
-    {
-      return;
-    }
+  if(GetCurrentRenderer() == NULL)
+    return;
   
-  int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
-  this->DeltaElevation = -20.0 / size[1];
-  this->DeltaAzimuth = -20.0 / size[0];
+  int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
+  double aDeltaElevation = -20.0 / size[1];
+  double aDeltaAzimuth = -20.0 / size[0];
   
-  rxf = (double)dx * this->DeltaAzimuth *  this->MotionFactor;
-  ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
+  double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
+  double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
   
-  cam = this->CurrentRenderer->GetActiveCamera();
+  vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
   cam->Azimuth(rxf);
   cam->Elevation(ryf);
   cam->OrthogonalizeViewUp();
-  ::ResetCameraClippingRange(this->CurrentRenderer); 
-  //this->Interactor->Render();
-  myGUIWindow->update();
+
+  GetCurrentRenderer()->ResetCameraClippingRange(); 
+
+  this->Render();
 }
 
 //----------------------------------------------------------------------------
@@ -239,8 +219,7 @@ SVTK_InteractorStyle
 ::PanXY(int x, int y, int oldX, int oldY)
 {
   TranslateView(x, y, oldX, oldY);   
-  //this->Interactor->Render();
-  myGUIWindow->update();
+  this->Render();
 }
 
 
@@ -249,23 +228,23 @@ void
 SVTK_InteractorStyle
 ::DollyXY(int dx, int dy)
 {
-  if (this->CurrentRenderer == NULL) return;
+  if (GetCurrentRenderer() == NULL) 
+    return;
 
-  double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
-  double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
+  double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]);
+  double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]);
 
   double zoomFactor = pow((double)1.1, dxf + dyf);
   
-  vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
+  vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
   if (aCam->GetParallelProjection())
     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
   else{
     aCam->Dolly(zoomFactor);
-    ::ResetCameraClippingRange(this->CurrentRenderer);
+    GetCurrentRenderer()->ResetCameraClippingRange(); 
   }
 
-  //this->Interactor->Render();
-  myGUIWindow->update();
+  this->Render();
 }
 
 //----------------------------------------------------------------------------
@@ -275,25 +254,122 @@ SVTK_InteractorStyle
 {
   vtkCamera *cam;
 
-  if (this->CurrentRenderer == NULL)
-    {
-      return;
-    }
+  if (GetCurrentRenderer() == NULL)
+    return;
 
-  double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
-                         (double)(x - this->CurrentRenderer->GetCenter()[0]));
-  double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
-                         (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
+  double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]),
+                         (double)(x - GetCurrentRenderer()->GetCenter()[0]));
+  double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]),
+                         (double)(oldX - GetCurrentRenderer()->GetCenter()[0]));
   
   newAngle *= this->RadianToDegree;
   oldAngle *= this->RadianToDegree;
 
-  cam = this->CurrentRenderer->GetActiveCamera();
+  cam = GetCurrentRenderer()->GetActiveCamera();
   cam->Roll(newAngle - oldAngle);
   cam->OrthogonalizeViewUp();
       
-  //this->Interactor->Render();
-  myGUIWindow->update();
+  this->Render();
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnConfigure() 
+{
+  this->FindPokedRenderer(0,0);
+  this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnMouseMove() 
+{
+  int x, y;
+  GetEventPosition( this->Interactor, x, y );
+  this->OnMouseMove( this->Interactor->GetControlKey(),
+                    this->Interactor->GetShiftKey(),
+                    x, y );
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnLeftButtonDown()
+{
+  int x, y;
+  GetEventPosition( this->Interactor, x, y );
+  this->OnLeftButtonDown( this->Interactor->GetControlKey(),
+                         this->Interactor->GetShiftKey(),
+                         x, y );
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnLeftButtonUp()
+{
+  int x, y;
+  GetEventPosition( this->Interactor, x, y );
+  this->OnLeftButtonUp( this->Interactor->GetControlKey(),
+                       this->Interactor->GetShiftKey(),
+                       x, y );
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnMiddleButtonDown() 
+{
+  int x, y;
+  GetEventPosition( this->Interactor, x, y );
+  this->OnMiddleButtonDown( this->Interactor->GetControlKey(),
+                           this->Interactor->GetShiftKey(),
+                           x, y );
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnMiddleButtonUp()
+{
+  int x, y;
+  GetEventPosition( this->Interactor, x, y );
+  this->OnMiddleButtonUp( this->Interactor->GetControlKey(),
+                         this->Interactor->GetShiftKey(),
+                         x, y );
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnRightButtonDown() 
+{
+  int x, y;
+  GetEventPosition( this->Interactor, x, y );
+  this->OnRightButtonDown( this->Interactor->GetControlKey(),
+                          this->Interactor->GetShiftKey(),
+                          x, y );
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnRightButtonUp()
+{
+  int x, y;
+  GetEventPosition( this->Interactor, x, y );
+  this->OnRightButtonUp( this->Interactor->GetControlKey(),
+                        this->Interactor->GetShiftKey(),
+                        x, y );
 }
 
 
@@ -318,14 +394,10 @@ SVTK_InteractorStyle
 ::OnLeftButtonDown(int ctrl, int shift, 
                   int x, int y) 
 {
-  if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
-    this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
-    return;
-  }
   this->FindPokedRenderer(x, y);
-  if (this->CurrentRenderer == NULL) {
+  if(GetCurrentRenderer() == NULL)
     return;
-  }
+
   myShiftState = shift;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
@@ -369,16 +441,10 @@ SVTK_InteractorStyle
                     int shift, 
                     int x, int y) 
 {
-  if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) 
-    {
-      this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
-      return;
-    }
   this->FindPokedRenderer(x, y);
-  if (this->CurrentRenderer == NULL)
-    {
-      return;
-    }
+  if(GetCurrentRenderer() == NULL)
+    return;
+
   myShiftState = shift;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
@@ -420,16 +486,10 @@ SVTK_InteractorStyle
                    int shift, 
                    int x, int y) 
 {
-  if (this->HasObserver(vtkCommand::RightButtonPressEvent)) 
-    {
-      this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
-      return;
-    }
   this->FindPokedRenderer(x, y);
-  if (this->CurrentRenderer == NULL)
-    {
-      return;
-    }
+  if(GetCurrentRenderer() == NULL)
+    return;
+
   myShiftState = shift;
   // finishing current viewer operation
   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
@@ -547,33 +607,17 @@ void
 SVTK_InteractorStyle
 ::loadCursors()
 {
-  myDefCursor       = QCursor(ArrowCursor);
-  myHandCursor      = QCursor(PointingHandCursor);
-  myPanCursor       = QCursor(SizeAllCursor);
+  myDefCursor       = QCursor(Qt::ArrowCursor);
+  myHandCursor      = QCursor(Qt::PointingHandCursor);
+  myPanCursor       = QCursor(Qt::SizeAllCursor);
   myZoomCursor      = QCursor(QPixmap(imageZoomCursor));
   myRotateCursor    = QCursor(QPixmap(imageRotateCursor));
   mySpinCursor      = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
-  myGlobalPanCursor = QCursor(CrossCursor);
+  myGlobalPanCursor = QCursor(Qt::CrossCursor);
   myCursorState     = false;
 }
 
 
-//----------------------------------------------------------------------------
-// event filter - controls mouse and keyboard events during viewer operations
-bool
-SVTK_InteractorStyle
-::eventFilter(QObject* object, QEvent* event)
-{
-  if (!myGUIWindow) return false;
-  if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
-  {
-    qApp->removeEventFilter(this);
-    startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
-  }
-  return QObject::eventFilter(object, event);
-}
-
-
 //----------------------------------------------------------------------------
 // starts Zoom operation (e.g. through menu command)
 void
@@ -587,7 +631,6 @@ SVTK_InteractorStyle
   }
   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
-  qApp->installEventFilter(this);
 }
 
 
@@ -604,7 +647,6 @@ SVTK_InteractorStyle
   }
   setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
-  qApp->installEventFilter(this);
 }
 
 //----------------------------------------------------------------------------
@@ -620,7 +662,6 @@ SVTK_InteractorStyle
   }
   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
-  qApp->installEventFilter(this);
 }
 
 
@@ -637,7 +678,6 @@ SVTK_InteractorStyle
   }
   setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
-  qApp->installEventFilter(this);
 }
 
 
@@ -655,7 +695,6 @@ SVTK_InteractorStyle
   }
   setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
-  qApp->installEventFilter(this);
 }
 
 
@@ -674,28 +713,11 @@ SVTK_InteractorStyle
   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
 
   // store current zoom scale
-  vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
-  myScale = cam->GetParallelScale();
-
-  if (myViewWindow) myViewWindow->onFitAll();
-
-  if (myGUIWindow) myGUIWindow->update();
-  
-  qApp->installEventFilter(this);
-}
+  myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale();
 
+  GetCurrentRenderer()->ResetCamera();
 
-//----------------------------------------------------------------------------
-// returns TRUE if needs redrawing
-bool
-SVTK_InteractorStyle
-::needsRedrawing()
-{
-  return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM   ||
-         State == VTK_INTERACTOR_STYLE_CAMERA_PAN    ||
-         State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
-         State == VTK_INTERACTOR_STYLE_CAMERA_SPIN   ||
-         State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
+  this->Render();
 }
 
 
@@ -708,30 +730,31 @@ SVTK_InteractorStyle
          const int right, 
          const int bottom)
 {
-  if (this->CurrentRenderer == NULL) return;
+  if (GetCurrentRenderer() == NULL) 
+    return;
  
   // move camera
   int x = (left + right)/2;
   int y = (top + bottom)/2;
-  int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
+  int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
   int oldX = aSize[0]/2;
   int oldY = aSize[1]/2;
   TranslateView(oldX, oldY, x, y);
 
   // zoom camera
-  double dxf = (double)(aSize[0]) / (double)(abs(right - left));
-  double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
+  double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left));
+  double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top));
   double zoomFactor = (dxf + dyf)/2 ;
 
-  vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
+  vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
   if(aCam->GetParallelProjection())
     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
   else{
     aCam->Dolly(zoomFactor);
-    ::ResetCameraClippingRange(this->CurrentRenderer);
+    GetCurrentRenderer()->ResetCameraClippingRange();
   }
   
-  myGUIWindow->update();
+  this->Render();
 }
 
 
@@ -772,37 +795,37 @@ void
 SVTK_InteractorStyle
 ::setCursor(const int operation)
 {
-  if (!myGUIWindow) return;
+  if (!GetRenderWidget()) return;
   switch (operation)
   {
     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
-      myGUIWindow->setCursor(myZoomCursor); 
+      GetRenderWidget()->setCursor(myZoomCursor); 
       myCursorState = true;
       break;
     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
-      myGUIWindow->setCursor(myPanCursor); 
+      GetRenderWidget()->setCursor(myPanCursor); 
       myCursorState = true;
       break;
     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
-      myGUIWindow->setCursor(myRotateCursor); 
+      GetRenderWidget()->setCursor(myRotateCursor); 
       myCursorState = true;
       break;
     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
-      myGUIWindow->setCursor(mySpinCursor); 
+      GetRenderWidget()->setCursor(mySpinCursor); 
       myCursorState = true;
       break;
     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
-      myGUIWindow->setCursor(myGlobalPanCursor); 
+      GetRenderWidget()->setCursor(myGlobalPanCursor); 
       myCursorState = true;
       break;
     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
-      myGUIWindow->setCursor(myHandCursor); 
+      GetRenderWidget()->setCursor(myHandCursor); 
       myCursorState = true;
       break;
     case VTK_INTERACTOR_STYLE_CAMERA_NONE:
     default:
-      myGUIWindow->setCursor(myDefCursor); 
+      GetRenderWidget()->setCursor(myDefCursor); 
       myCursorState = false;
       break;
   }
@@ -815,14 +838,14 @@ void
 SVTK_InteractorStyle
 ::onStartOperation()
 {
-  if (!myGUIWindow) return;
+  if (!GetRenderWidget()) return;
   // VSV: LOD actor activisation
   //  this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
   switch (State) {
     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
     {
-      QPainter p(myGUIWindow);
+      QPainter p(GetRenderWidget());
       p.setPen(Qt::lightGray);
       p.setRasterOp(Qt::XorROP);
       p.drawRect(QRect(myPoint, myOtherPoint));
@@ -844,286 +867,81 @@ void
 SVTK_InteractorStyle
 ::onFinishOperation() 
 {
-  if (!myGUIWindow
+  if (!GetRenderWidget()
     return;
 
   // VSV: LOD actor activisation
   //  rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
 
-  Selection_Mode aSelectionMode = myViewWindow->SelectionMode();
-  bool aSelActiveCompOnly = false;
-
-  QString aComponentDataType;
-  if(SUIT_Session* aSession = SUIT_Session::session())
-    if(SUIT_Application* aSUITApp = aSession->activeApplication())
-      if(CAM_Application* aCAMApp = dynamic_cast<CAM_Application*>(aSUITApp))
-       if(CAM_Module* aModule = aCAMApp->activeModule())
-         aComponentDataType = aModule->name();
+  SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
 
   switch (State) {
     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
     {
-      QPainter p(myGUIWindow);
-      p.setPen(Qt::lightGray);
-      p.setRasterOp(Qt::XorROP);
-      QRect rect(myPoint, myOtherPoint);
-      p.drawRect(rect);
-      rect = rect.normalize();
+      QPainter aPainter(GetRenderWidget());
+      aPainter.setPen(Qt::lightGray);
+      aPainter.setRasterOp(Qt::XorROP);
+      QRect aRect(myPoint, myOtherPoint);
+      aPainter.drawRect(aRect);
+      aRect = aRect.normalize();
+
       if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
         // making fit rect opeation 
         int w, h;
-        myInteractor->GetSize(w, h);
-        int x1, y1, x2, y2;
-        x1 = rect.left(); 
-        y1 = h - rect.top() - 1;
-        x2 = rect.right(); 
-        y2 = h - rect.bottom() - 1;
+        Interactor->GetSize(w, h);
+        int x1 = aRect.left(); 
+        int y1 = h - aRect.top() - 1;
+        int x2 = aRect.right(); 
+        int y2 = h - aRect.bottom() - 1;
         fitRect(x1, y1, x2, y2);
       }
       else {
         if (myPoint == myOtherPoint) {
          // process point selection
-          int w, h, x, y;
-          myInteractor->GetSize(w, h);
-          x = myPoint.x(); 
-          y = h - myPoint.y() - 1;
-
-          this->FindPokedRenderer(x, y);
-         myInteractor->StartPickCallback();
-
-         vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker());
-          aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
-    
-         SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
-
-          if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
-           int aVtkId = picker->GetCellId();
-           if ( aVtkId >= 0 && aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) {
-             int anObjId = aSActor->GetElemObjId(aVtkId);
-             if(anObjId >= 0){
-               Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
-               if(aSelectionMode != EdgeOfCellSelection) {
-                 if(CheckDimensionId(aSelectionMode,aSActor,anObjId)){
-                   if (GetSelector()->IsSelected(anIO)) {
-                     // This IO is already in the selection
-                     GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
-                   } else {
-                     if (!myShiftState) {
-                       this->HighlightProp( NULL );
-                       GetSelector()->ClearIObjects();
-                     }
-                     GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
-                     GetSelector()->AddIObject(aSActor);
-                   }
-                 }
-               }else{
-                 if (!myShiftState) {
-                   this->HighlightProp( NULL );
-                   GetSelector()->ClearIObjects();
-                 }
-                 int anEdgeId = GetEdgeId(picker,aSActor,anObjId);
-                 if (anEdgeId >= 0) {
-                   GetSelector()->AddOrRemoveIndex(anIO,anObjId,false);
-                   GetSelector()->AddOrRemoveIndex(anIO,-anEdgeId-1,true);
-                   GetSelector()->AddIObject(aSActor);
-                 } 
-               }
-             }
-           } else if( !myShiftState )
-           {
-             this->HighlightProp( NULL );
-             GetSelector()->ClearIObjects();
-           }
-          } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
-           int aVtkId = picker->GetPointId();
-           if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) {
-             if ( aSActor && aSActor->hasIO() ) {
-               int anObjId = aSActor->GetNodeObjId(aVtkId);
-               if(anObjId >= 0){
-                 Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
-                 if(GetSelector()->IsSelected(anIO)) {
-                   // This IO is already in the selection
-                   GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
-                 } else {
-                   if(!myShiftState) {
-                     this->HighlightProp( NULL );
-                     GetSelector()->ClearIObjects();
-                   }
-                   GetSelector()->AddOrRemoveIndex(anIO,anObjId,myShiftState);
-                   GetSelector()->AddIObject(aSActor);
-                 }
-               }
-             }
-           } else {
-             this->HighlightProp( NULL );
-             GetSelector()->ClearIObjects();
-           } 
-         } else {
-           if ( aSActor && aSActor->hasIO() ) {
-             this->PropPicked++;
-             Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
-             if(GetSelector()->IsSelected(anIO)) {
-               // This IO is already in the selection
-               if(myShiftState) {
-                 GetSelector()->RemoveIObject(aSActor);
-               }
-             }
-             else {
-               if(!myShiftState) {
-                 this->HighlightProp( NULL );
-                 GetSelector()->ClearIObjects();
-               }
-               GetSelector()->AddIObject(aSActor);
-             }
-           }else{
-             // No selection clear all
-             this->PropPicked = 0;
-             this->HighlightProp( NULL );
+          this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
+         Interactor->StartPickCallback();
+
+          myPicker->Pick(aSelectionEvent->myX, 
+                        aSelectionEvent->myY, 
+                        0.0, 
+                        GetCurrentRenderer());
+         //
+         SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer());
+         aSelectionEvent->myIsRectangle = false;
+         if(anActor){
+           anActor->Highlight( this, aSelectionEvent, true );
+         }else{
+           if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != anActor)
+             myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
+           if(!myShiftState)
              GetSelector()->ClearIObjects();
-           }
          }
-         myInteractor->EndPickCallback();
-        } else {
+         myLastHighlitedActor = anActor;
+       } 
+       else {
           //processing rectangle selection
-         if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
-         myInteractor->StartPickCallback();
+         Interactor->StartPickCallback();
+         GetSelector()->StartPickCallback();
+         aSelectionEvent->myIsRectangle = true;
 
-         if (!myShiftState) {
-           this->PropPicked = 0;
-           this->HighlightProp( NULL );
+         if(!myShiftState)
            GetSelector()->ClearIObjects();
-         }
 
-         // Compute bounds
-         //      vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
-         QRect rect(myPoint, myOtherPoint);
-         rect = rect.normalize();
-         int w, h;
-         myInteractor->GetSize(w, h);
-         int x1, y1, x2, y2;
-         x1 = rect.left(); 
-         y1 = h - rect.top() - 1;
-         x2 = rect.right(); 
-         y2 = h - rect.bottom() - 1;
-
-         switch (aSelectionMode) {
-         case NodeSelection: {
-           if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(myInteractor->GetPicker()) ) {
-             vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
-             aListActors->InitTraversal();
-             while (vtkActor* aActor = aListActors->GetNextActor()) {
-               if (!aActor->GetVisibility()) 
-                 continue;
-               if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
-                 if (aSActor->hasIO()) {
-                   Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
-                   if (anIO.IsNull()) 
-                     continue;
-                   if (aSelActiveCompOnly && aComponentDataType != anIO->getComponentDataType())
-                     continue;
-                   if (vtkDataSet* aDataSet = aSActor->GetInput()) {
-                     TColStd_MapOfInteger anIndices;
-                     for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
-                       float aPoint[3];
-                       aDataSet->GetPoint(i,aPoint);
-                       if (IsInRect(aPoint,x1,y1,x2,y2)){
-                         float aDisp[3];
-                         ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
-                         if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
-                           if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
-                             if(anActorCollection->IsItemPresent(aSActor)){
-                               float aPickedPoint[3];
-                               aPointPicker->GetMapperPosition(aPickedPoint);
-                               vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
-                               if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ){
-                                 int anObjId = aSActor->GetNodeObjId(aVtkId);
-                                 anIndices.Add(anObjId);
-                               }
-                             }
-                           }
-                         }
-                       }
-                     }
-                     if (!anIndices.IsEmpty()) {
-                       GetSelector()->AddOrRemoveIndex(anIO,anIndices,true); // ENK false to true
-                       GetSelector()->AddIObject(aSActor);
-                       anIndices.Clear();
-                     }else{
-                       GetSelector()->RemoveIObject(aSActor);
-                     }
-                   }
-                 }
+         vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors();
+         aListActors->InitTraversal();
+         while(vtkActor* aActor = aListActors->GetNextActor()){
+           if(aActor->GetVisibility()){
+             if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)){
+               if(aSActor->hasIO()){
+                 aSActor->Highlight( this, aSelectionEvent, true );
                }
              }
            }
-           break;
          }
-         case CellSelection:
-         case EdgeOfCellSelection:
-         case EdgeSelection:
-         case FaceSelection:
-         case VolumeSelection: 
-           {
-             vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
-             picker->SetTolerance(0.001);
-             picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
-             
-             vtkActorCollection* aListActors = picker->GetActors();
-             aListActors->InitTraversal();
-             while(vtkActor* aActor = aListActors->GetNextActor()) {
-               if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
-                 if (aSActor->hasIO()) {
-                   Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
-                   if (aSelActiveCompOnly && aComponentDataType != anIO->getComponentDataType())
-                     continue;
-                   VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
-                   if ( !cellList.empty() ) {
-                     TColStd_MapOfInteger anIndexes;
-                     VTKViewer_CellDataSet::iterator it;
-                     for ( it = cellList.begin(); it != cellList.end(); ++it ) {
-                       int aCellId = (*it).cellId;
-                       
-                       if ( !IsValid( aSActor, aCellId ) )
-                         continue;
-                       
-                       int anObjId = aSActor->GetElemObjId(aCellId);
-                       if (anObjId != -1){
-                         if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
-                           anIndexes.Add(anObjId);
-                         }
-                       }
-                     }
-                     GetSelector()->AddOrRemoveIndex(anIO,anIndexes,true);
-                     GetSelector()->AddIObject(aSActor);
-                   }
-                 }
-               }
-             }
-           }
-           break;          
-         case ActorSelection: // objects selection
-           {
-             vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
-             picker->SetTolerance(0.001);
-             picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
-
-             vtkActorCollection* aListActors = picker->GetActors();
-             aListActors->InitTraversal();
-             while(vtkActor* aActor = aListActors->GetNextActor()) {
-               if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
-                 if (aSActor->hasIO()) {
-                   Handle(SALOME_InteractiveObject) anIO = aSActor->getIO();
-                   GetSelector()->AddIObject(aSActor);
-                   this->PropPicked++;
-                 }
-               }
-             }
-           } // end case 4
-         } //end switch
-         myInteractor->EndPickCallback();
        }
-       myViewWindow->onSelectionChanged();
+       Interactor->EndPickCallback();
+       GetSelector()->EndPickCallback();
       } 
     } 
     break;
@@ -1135,55 +953,48 @@ SVTK_InteractorStyle
   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
     {
       int w, h, x, y;
-      myInteractor->GetSize(w, h);
+      Interactor->GetSize(w, h);
       x = myPoint.x(); 
       y = h - myPoint.y() - 1;
       Place(x, y);
     }
     break;
   }
-  if (myGUIWindow) myGUIWindow->update();
 
+  this->Render();
 }
 
 
 // called during viewer operation when user moves mouse (!put necessary processing here!)
+//----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
 ::onOperation(QPoint mousePos) 
 {
-  if (!myGUIWindow) return;
-  int w, h;
-  GetInteractor()->GetSize(w, h);
+  if (!GetRenderWidget()) 
+    return;
+
   switch (State) {
   case VTK_INTERACTOR_STYLE_CAMERA_PAN: 
     {
-      // processing panning
-      //this->FindPokedCamera(mousePos.x(), mousePos.y());
       this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
       myPoint = mousePos;
       break;
     }
   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: 
     {    
-      // processing zooming
-      //this->FindPokedCamera(mousePos.x(), mousePos.y());
       this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
       myPoint = mousePos;
       break;
     }
   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: 
     {
-      // processing rotation
-      //this->FindPokedCamera(mousePos.x(), mousePos.y());
       this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
       myPoint = mousePos;
       break;
     }
   case VTK_INTERACTOR_STYLE_CAMERA_SPIN: 
     {
-      // processing spinning
-      //this->FindPokedCamera(mousePos.x(), mousePos.y());
       this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
       myPoint = mousePos;
       break;
@@ -1199,7 +1010,7 @@ SVTK_InteractorStyle
     }
   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
     {
-      QPainter p(myGUIWindow);
+      QPainter p(GetRenderWidget());
       p.setPen(Qt::lightGray);
       p.setRasterOp(Qt::XorROP);
       p.drawRect(QRect(myPoint, myOtherPoint));
@@ -1208,182 +1019,73 @@ SVTK_InteractorStyle
       break;
     }
   }
-  this->LastPos[0] = mousePos.x();
-  this->LastPos[1] = h - mousePos.y() - 1;
-}
-
-// called when selection mode changed (!put necessary initialization here!)
-void
-SVTK_InteractorStyle
-::OnSelectionModeChanged()
-{
-  
-  myPreSelectionActor->SetVisibility(false);
-  myElemId = myEdgeId = myNodeId = -1;
-  mySelectedActor = NULL;
 }
 
 // called when user moves mouse inside viewer window and there is no active viewer operation 
 // (!put necessary processing here!)
+//----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
 ::onCursorMove(QPoint mousePos) 
 {
   // processing highlighting
-  Selection_Mode aSelectionMode = myViewWindow->SelectionMode();
-
-  int w, h, x, y;
-  myInteractor->GetSize(w, h);
-  x = mousePos.x(); y = h - mousePos.y() - 1;
+  SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
+  this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
 
-  this->FindPokedRenderer(x,y);
-  myInteractor->StartPickCallback();
-  myPreSelectionActor->SetVisibility(false);
+  bool anIsChanged = false;
 
-  vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker());
-  aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
+  myPicker->Pick(aSelectionEvent->myX, 
+                aSelectionEvent->myY, 
+                0.0, 
+                GetCurrentRenderer());
+  
+  SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer());
+  if (anActor){
+    anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
+  }
 
-  SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
+  if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor)
+    anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );   
 
-  if (aSActor && myPreSelectionActor){
-    float aPos[3];
-    aSActor->GetPosition(aPos);
-    myPreSelectionActor->SetPosition(aPos);
-  }
+  myLastPreHighlitedActor = anActor;
 
-  if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
-    int aVtkId = picker->GetCellId();
-    if ( aVtkId >= 0 ) {
-      int anObjId = aSActor->GetElemObjId(aVtkId);
-      if ( aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) {
-       bool anIsSameObjId = (mySelectedActor == aSActor && myElemId == anObjId);
-       bool aResult = anIsSameObjId;
-       if(!anIsSameObjId) {
-         if(aSelectionMode != EdgeOfCellSelection) {
-           aResult = CheckDimensionId(aSelectionMode,aSActor,anObjId);
-           if(aResult){
-             mySelectedActor = aSActor;
-             myElemId = anObjId;
-             myInteractor->setCellData(anObjId,aSActor,myPreSelectionActor);
-           }
-         }
-       }
-       if(aSelectionMode == EdgeOfCellSelection){
-         int anEdgeId = GetEdgeId(picker,aSActor,anObjId);
-         bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
-         aResult = anIsSameEdgeId;
-         if(!anIsSameEdgeId) {
-           aResult = (anEdgeId >= 0);
-           if (aResult) {
-             mySelectedActor = aSActor;
-             myEdgeId = anEdgeId;
-             myElemId = anObjId;
-             myInteractor->setEdgeData(anObjId,aSActor,-anEdgeId-1,myPreSelectionActor);
-           } 
-         }
-       }
-       if(aResult) {
-         myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
-         myPreSelectionActor->SetVisibility(true);
-       }
-      }
-    }
-  }
-  else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
-    int aVtkId = picker->GetPointId();
-    if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) {
-      if ( aSActor && aSActor->hasIO() ) {
-       int anObjId = aSActor->GetNodeObjId(aVtkId);
-       bool anIsSameObjId = (mySelectedActor == aSActor && myNodeId == anObjId);
-       if(!anIsSameObjId) {
-         mySelectedActor = aSActor;
-         myNodeId = anObjId;
-         myInteractor->setPointData(anObjId,aSActor,myPreSelectionActor);
-       }
-       myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
-       myPreSelectionActor->SetVisibility(true);
-      }
-    }
-  }
-  else if ( vtkPicker::SafeDownCast(aPicker) ) {
-    if ( aSActor ) {
-      if ( myPreViewActor != aSActor ) {
-       if ( myPreViewActor != NULL ) {
-         myPreViewActor->SetPreSelected( false );
-       }
-       myPreViewActor = aSActor;
-             
-       if ( aSActor->hasIO() ) {
-         Handle( SALOME_InteractiveObject) IO = aSActor->getIO();
-         if ( !GetSelector()->IsSelected(IO) ) {
-            // Find All actors with same IO
-           vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
-           theActors->InitTraversal();
-           while( vtkActor *ac = theActors->GetNextActor() ) {
-             if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
-               if ( anActor->hasIO() ) {
-                 Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
-                 if(IO->isSame(IOS)) {
-                   anActor->SetPreSelected( true );
-                 }
-               }
-             }
-           }
-         }
-       }
-      }
-    } else {
-      myPreViewActor = NULL;
-      vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
-      theActors->InitTraversal();
-      while( vtkActor *ac = theActors->GetNextActor() ) {
-        if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
-          anActor->SetPreSelected( false );
-        }
-      }
-    }
-  }
-  myInteractor->EndPickCallback();
-  //myInteractor->Render();
-  myGUIWindow->update();
-  
-  this->LastPos[0] = x;
-  this->LastPos[1] = y;
+  if(anIsChanged)
+    this->Render();
 }
 
 // called on finsh GlobalPan operation 
+//----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
 ::Place(const int theX, const int theY) 
 {
-  if (this->CurrentRenderer == NULL) {
+  if (GetCurrentRenderer() == NULL)
     return;
-  }
 
   //translate view
-  int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
+  int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
   int centerX = aSize[0]/2;
   int centerY = aSize[1]/2;
 
   TranslateView(centerX, centerY, theX, theY);
 
   // restore zoom scale
-  vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
+  vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
   cam->SetParallelScale(myScale);
-  ::ResetCameraClippingRange(this->CurrentRenderer);
-
-  if (myGUIWindow) myGUIWindow->update();
+  GetCurrentRenderer()->ResetCameraClippingRange();
 
+  this->Render();
 }
 
 
 
 // Translates view from Point to Point
+//----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
 ::TranslateView(int toX, int toY, int fromX, int fromY)
 {
-  vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
+  vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
   double viewFocus[4], focalDepth, viewPoint[3];
   float newPickPoint[4], oldPickPoint[4], motionVector[3];
   cam->GetFocalPoint(viewFocus);
@@ -1412,135 +1114,310 @@ SVTK_InteractorStyle
                   motionVector[2] + viewPoint[2]);
 }
 
-
-/// Checks: is the given Actor within display coordinates?
-bool
+//----------------------------------------------------------------------------
+void
 SVTK_InteractorStyle
-::IsInRect(vtkActor* theActor, 
-          const int left, const int top, 
-          const int right, const int bottom)
-{
-  float* aBounds = theActor->GetBounds();
-  float aMin[3], aMax[3];
-  ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
-  ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
-  if (aMin[0] > aMax[0]) {
-    float aBuf = aMin[0];
-    aMin[0] = aMax[0];
-    aMax[0] = aBuf;
-  }
-  if (aMin[1] > aMax[1]) {
-    float aBuf = aMin[1];
-    aMin[1] = aMax[1];
-    aMax[1] = aBuf;    
-  }
-
-  return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
+::IncrementalPan( const int incrX, const int incrY )
+{
+  this->PanXY( incrX, incrY, 0, 0 );
 }
 
-
-/// Checks: is the given Cell within display coordinates?
-bool
+//----------------------------------------------------------------------------
+void
 SVTK_InteractorStyle
-::IsInRect(vtkCell* theCell, 
-          const int left, const int top, 
-          const int right, const int bottom)
-{
-  float* aBounds = theCell->GetBounds();
-  float aMin[3], aMax[3];
-  ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
-  ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
-  if (aMin[0] > aMax[0]) {
-    float aBuf = aMin[0];
-    aMin[0] = aMax[0];
-    aMax[0] = aBuf;
-  }
-  if (aMin[1] > aMax[1]) {
-    float aBuf = aMin[1];
-    aMin[1] = aMax[1];
-    aMax[1] = aBuf;    
-  }
-
-  return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
+::IncrementalZoom( const int incr )
+{
+  this->DollyXY( incr, incr );
 }
 
-
-bool
+//----------------------------------------------------------------------------
+void
 SVTK_InteractorStyle
-::IsInRect(float* thePoint, 
-          const int left, const int top, 
-          const int right, const int bottom)
+::IncrementalRotate( const int incrX, const int incrY )
 {
-  float aPnt[3];
-  ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
-
-  return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
+  this->RotateXY( incrX, -incrY );
 }
 
+//----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
-::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
+::SetInteractor( vtkRenderWindowInteractor* theInteractor )
 {
-  myFilters[ theFilter->GetId() ] = theFilter;
+  // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
+  Superclass::SetInteractor( theInteractor );
+  myInteractor = dynamic_cast<SVTK_GenericRenderWindowInteractor*>(theInteractor);
+
+  if(theInteractor) { 
+    // register EventCallbackCommand as observer of custorm event (3d space mouse event)
+    theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority );
+
+    theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority );
+
+    theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority );
+  }
 }
 
-bool
+
+//----------------------------------------------------------------------------
+void
 SVTK_InteractorStyle
-::IsFilterPresent( const int theId )
+::OnTimer() 
 {
-  return myFilters.find( theId ) != myFilters.end();
+  //vtkInteractorStyle::OnTimer();
+  this->Interactor->Render();
 }
 
-void  
+//----------------------------------------------------------------------------
+void
 SVTK_InteractorStyle
-::RemoveFilter( const int theId )
+::Render() 
 {
-  if ( IsFilterPresent( theId ) )
-    myFilters.erase( theId );
+  this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
 }
 
-
-bool
+//----------------------------------------------------------------------------
+void
 SVTK_InteractorStyle
-::IsValid( SALOME_Actor* theActor,
-          const int     theId,
-          const bool    theIsNode )
+::onSpaceMouseMove( double* data )
 {
-  std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
-  for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
-  {
-    const Handle(VTKViewer_Filter)& aFilter = anIter->second;
-    if ( theIsNode == aFilter->IsNodeFilter() &&
-         !aFilter->IsValid( theActor, theId ) )
-      return false;
-  }
-  return true;
+  // general things, do SetCurrentRenderer() within FindPokedRenderer() 
+  int x, y;
+  GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
+  FindPokedRenderer( x, y ); // calls SetCurrentRenderer
+  
+  IncrementalZoom( (int)data[2] );        // 1. push toward / pull backward = zoom out / zoom in
+  IncrementalPan(  (int)data[0],  (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
+  IncrementalRotate( 0,  (int)data[4] );   // 4. twist the control = rotate around Y axis
+  IncrementalRotate( (int)data[3], 0  );   // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
 }
 
-Handle(VTKViewer_Filter) 
+//----------------------------------------------------------------------------
+void
 SVTK_InteractorStyle
-::GetFilter( const int theId )
+::onSpaceMouseButton( int button )
 {
-  return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
+  if( mySMDecreaseSpeedBtn == button ) {   
+    ControllerIncrement()->Decrease();
+  }
+  if( mySMIncreaseSpeedBtn == button ) {    
+    ControllerIncrement()->Increase();
+  }
+  if( mySMDominantCombinedSwitchBtn == button )    
+    DominantCombinedSwitch();
 }
 
+//----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
-::IncrementalPan( const int incrX, const int incrY )
+::DominantCombinedSwitch()
 {
-  this->PanXY( incrX, incrY, 0, 0 );
+  printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
 }
 
+//----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
-::IncrementalZoom( const int incr )
+::ProcessEvents( vtkObject* object,
+                unsigned long event,
+                void* clientData, 
+                void* callData )
 {
-  this->DollyXY( incr, incr );
+  if ( clientData ) {
+    vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
+    SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
+    int aSpeedIncrement=self->ControllerIncrement()->Current();
+    if ( self ) {
+      switch ( event ) {
+      case SVTK::SpaceMouseMoveEvent : 
+       self->onSpaceMouseMove( (double*)callData ); 
+       return;
+      case SVTK::SpaceMouseButtonEvent : 
+       self->onSpaceMouseButton( *((int*)callData) ); 
+       return;
+      case SVTK::PanLeftEvent: 
+       self->IncrementalPan(-aSpeedIncrement, 0);
+       return;
+      case SVTK::PanRightEvent:
+       self->IncrementalPan(aSpeedIncrement, 0);
+       return;
+      case SVTK::PanUpEvent:
+       self->IncrementalPan(0, aSpeedIncrement);
+       return;
+      case SVTK::PanDownEvent:
+       self->IncrementalPan(0, -aSpeedIncrement);
+       return;
+      case SVTK::ZoomInEvent:
+       self->IncrementalZoom(aSpeedIncrement);
+       return;
+      case SVTK::ZoomOutEvent:
+       self->IncrementalZoom(-aSpeedIncrement);
+       return;
+      case SVTK::RotateLeftEvent: 
+       self->IncrementalRotate(-aSpeedIncrement, 0);
+       return;
+      case SVTK::RotateRightEvent:
+       self->IncrementalRotate(aSpeedIncrement, 0);
+       return;
+      case SVTK::RotateUpEvent:
+       self->IncrementalRotate(0, -aSpeedIncrement);
+       return;
+      case SVTK::RotateDownEvent:
+       self->IncrementalRotate(0, aSpeedIncrement);
+       return;
+      case SVTK::PlusSpeedIncrementEvent:
+       self->ControllerIncrement()->Increase();
+       return;
+      case SVTK::MinusSpeedIncrementEvent:
+       self->ControllerIncrement()->Decrease();
+       return;
+      case SVTK::SetSpeedIncrementEvent:
+       self->ControllerIncrement()->SetStartValue(*((int*)callData));
+       return;
+
+      case SVTK::SetSMDecreaseSpeedEvent:
+       self->mySMDecreaseSpeedBtn = *((int*)callData);
+       return;
+      case SVTK::SetSMIncreaseSpeedEvent:
+       self->mySMIncreaseSpeedBtn = *((int*)callData);
+       return;
+      case SVTK::SetSMDominantCombinedSwitchEvent:
+       self->mySMDominantCombinedSwitchBtn = *((int*)callData);
+       return;
+
+      case SVTK::StartZoom:
+       self->startZoom();
+       return;
+      case SVTK::StartPan:
+       self->startPan();
+       return;
+      case SVTK::StartRotate:
+       self->startRotate();
+       return;
+      case SVTK::StartGlobalPan:
+       self->startGlobalPan();
+       return;
+      case SVTK::StartFitArea:
+       self->startFitArea();
+       return;
+      }
+    }
+  }
+
+  Superclass::ProcessEvents( object, event, clientData, callData );
+}
+//----------------------------------------------------------------------------
+void SVTK_InteractorStyle::OnChar()
+{
+}
+//----------------------------------------------------------------------------
+void SVTK_InteractorStyle::OnKeyDown()
+{
+  bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
+  if (bInvokeSuperclass){
+    Superclass::OnKeyDown();
+  }
+}
+//----------------------------------------------------------------------------
+void SVTK_InteractorStyle::ActionPicking()
+{
+  int x, y;
+  Interactor->GetEventPosition( x, y ); 
+  FindPokedRenderer( x, y ); 
+  
+  myOtherPoint = myPoint = QPoint(x, y);
+  
+  startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
+  onFinishOperation();
+  startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
+}
+//----------------------------------------------------------------------------
+void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
+{
+  myControllerOnKeyDown=theController;
+}
+//----------------------------------------------------------------------------
+SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
+{
+  return myControllerOnKeyDown.GetPointer();
+}
+//----------------------------------------------------------------------------
+void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
+{
+  myControllerIncrement=theController;
+}
+//----------------------------------------------------------------------------
+SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
+{
+  return myControllerIncrement.GetPointer();
 }
 
-void
-SVTK_InteractorStyle
-::IncrementalRotate( const int incrX, const int incrY )
+vtkStandardNewMacro(SVTK_ControllerIncrement);
+//----------------------------------------------------------------------------
+SVTK_ControllerIncrement::SVTK_ControllerIncrement()
 {
-  this->RotateXY( incrX, -incrY );
+  myIncrement=10;
+}
+//----------------------------------------------------------------------------
+SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
+{
+}
+//----------------------------------------------------------------------------
+void SVTK_ControllerIncrement::SetStartValue(const int theValue)
+{
+  myIncrement=theValue;
+}
+//----------------------------------------------------------------------------
+int SVTK_ControllerIncrement::Current()const
+{
+  return myIncrement;
+}
+//----------------------------------------------------------------------------
+int SVTK_ControllerIncrement::Increase()
+{
+  ++myIncrement;
+  return myIncrement;
+}
+//----------------------------------------------------------------------------
+int SVTK_ControllerIncrement::Decrease()
+{
+  if (myIncrement>1){
+    --myIncrement;
+  }
+  return myIncrement;
+}
+
+vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
+//----------------------------------------------------------------------------
+SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
+{
+}
+//----------------------------------------------------------------------------
+SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
+{
+}
+//----------------------------------------------------------------------------
+bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)
+{
+  return true;
 }
index 53039e86b4f07cd6166fca025b99bfb4294c92ba..7ea671df44c085df75c2b38134c0e82c65a30659 100644 (file)
 
 #include "SVTK.h"
 
-#include <vtkInteractorStyle.h>
+#include "SVTK_SelectionEvent.h"
 
-class vtkCell;
-class vtkRenderWindowInteractor;
+#include <boost/shared_ptr.hpp>
+
+#include <vtkInteractorStyle.h>
+#include <vtkSmartPointer.h>
 
-#include <qobject.h>
 #include <qcursor.h>
+#include <qevent.h>
 
 #include <map>
 
-#include "VTKViewer_Filter.h"
+#include <vtkObject.h>
+//
+//-------------------------------------------
+//! Control the value of increment  in SALOME way.
+/*!
+  This class controls of value of increment,
+  for pan/rotate/zoom operations in SALOME way
+*/
+class SVTK_ControllerIncrement : public vtkObject{
+ public:
+  vtkTypeMacro(SVTK_ControllerIncrement, vtkObject);
+  static SVTK_ControllerIncrement* New();
+
+  //! Set start value of increment
+  void SetStartValue(const int );
+
+  //! Get current value of increment
+  int Current()const;
 
-class VTKViewer_Trihedron;
+  //! Increace the increment value by add 1
+  virtual int Increase();
+
+  //! Decreace the increment value by subtract 1
+  virtual int Decrease();
+ protected:
+  SVTK_ControllerIncrement();
+  virtual ~SVTK_ControllerIncrement();
+ protected:
+  int  myIncrement;
+ private:
+  SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented
+  void operator=(const SVTK_ControllerIncrement&);          //Not implemented
+};
+//
+//-------------------------------------------
+//! Control the behaviour of KeyDown event in SALOME way.
+/*!
+  This class controls the behaviour of KeyDown event
+  in SALOME way
+*/
+class SVTK_ControllerOnKeyDown : public vtkObject{
+ public:
+  vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject);
+  static SVTK_ControllerOnKeyDown* New();
+
+  //! Provides the action on event 
+  virtual bool OnKeyDown(vtkInteractorStyle* );
+
+ protected:
+  SVTK_ControllerOnKeyDown();
+  virtual ~SVTK_ControllerOnKeyDown();
+  
+ private:
+  SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented
+  void operator=(const SVTK_ControllerOnKeyDown&);          //Not implemented
+};
+//-------------------------------------------
+
+class vtkCell;
+class vtkPicker;
 
 class SALOME_Actor;
-class SVTK_Actor;
-class SVTK_Viewer;
+
 class SVTK_Selector;
-class SVTK_ViewWindow;
-class SVTK_RenderWindowInteractor;
+class SVTK_GenericRenderWindowInteractor;
 
 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
@@ -61,63 +118,126 @@ class SVTK_RenderWindowInteractor;
 #define VTK_INTERACTOR_STYLE_CAMERA_SELECT     6
 #define VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN 7
 
-class SVTK_EXPORT SVTK_InteractorStyle : public QObject, 
-  public vtkInteractorStyle
+//! Introduce SALOME way of user interaction
+/*!
+  This class defines SALOME way of user interaction for VTK viewer, as well, 
+  as introduce a new selection mechanism
+*/
+class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle
 {
-  Q_OBJECT;
-
  public:
-  // Description:
-  // This class must be supplied with a vtkRenderWindowInteractor wrapper or
-  // parent. This class should not normally be instantiated by application
-  // programmers.
   static SVTK_InteractorStyle *New();
   vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle);
 
-  virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor);
-  void setViewWindow(SVTK_ViewWindow* theViewWindow);
-  void setGUIWindow(QWidget* theWindow);
+  typedef boost::shared_ptr<SVTK_SelectionEvent> PSelectionEvent;
 
-  virtual int GetState();
+  
 
-  //merge with V2_2_0_VISU_improvements:void setTriedron(VTKViewer_Trihedron* theTrihedron);
-  void setPreselectionProp(const double& theRed = 0, 
-                          const double& theGreen = 1,
-                          const double& theBlue = 1, 
-                          const int& theWidth = 5);
+  //! Generate special #SVTK_SelectionEvent
+  virtual
+  SVTK_SelectionEvent*
+  GetSelectionEvent();
 
-  // Generic event bindings must be overridden in subclasses
-  void OnMouseMove  (int ctrl, int shift, int x, int y);
-  void OnLeftButtonDown(int ctrl, int shift, int x, int y);
-  void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
-  void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
-  void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
-  void OnRightButtonDown(int ctrl, int shift, int x, int y);
-  void OnRightButtonUp  (int ctrl, int shift, int x, int y);
-
-  void OnSelectionModeChanged();
-
-  //merge with V2_2_0_VISU_improvements:void  ViewFitAll();
-
-  void                     SetFilter( const Handle(VTKViewer_Filter)& );
-  Handle(VTKViewer_Filter) GetFilter( const int );  
-  bool                     IsFilterPresent( const int );
-  void                     RemoveFilter( const int );
-  bool                     IsValid( SALOME_Actor* theActor,
-                                    const int     theId,
-                                    const bool    theIsNode = false );
+  //! Generate special #SVTK_SelectionEvent with flipped Y coordinate
+  virtual
+  SVTK_SelectionEvent*
+  GetSelectionEventFlipY();
+
+  //! Redefined in order to add an observer (callback) for custorm event (space mouse event)
+  virtual
+  void
+  SetInteractor( vtkRenderWindowInteractor* );
+
+  //! To invoke #vtkRenderWindowInteractor::CreateTimer
+  virtual 
+  void
+  Render();
+
+  //! To implement cached rendering
+  virtual
+  void
+  OnTimer();
+
+  //! To reset reset view
+  virtual
+  void
+  OnConfigure();
+
+  //! To handle mouse move event
+  virtual 
+  void
+  OnMouseMove();
+
+  //! To handle left mouse button down event (reimplemented from #vtkInteractorStyle)
+  virtual
+  void
+  OnLeftButtonDown();
+
+  //! To handle left mouse button up event (reimplemented from #vtkInteractorStyle)
+  virtual
+  void
+  OnLeftButtonUp();
+
+  //! To handle middle mouse button down event (reimplemented from #vtkInteractorStyle)
+  virtual
+  void
+  OnMiddleButtonDown();
+
+  //! To handle middle mouse button up event (reimplemented from #vtkInteractorStyle)
+  virtual
+  void
+  OnMiddleButtonUp();
+
+  //! To handle right mouse button down event (reimplemented from #vtkInteractorStyle)
+  virtual
+  void
+  OnRightButtonDown();
+
+  //! To handle right mouse button up event (reimplemented from #vtkInteractorStyle)
+  virtual
+  void
+  OnRightButtonUp();
+
+  //! To handle keyboard event (reimplemented from #vtkInteractorStyle)
+  virtual
+  void
+  OnChar();
+
+  //! To set current increment controller 
+  void SetControllerIncrement(SVTK_ControllerIncrement*);
+
+  //! To get current increment controller 
+  SVTK_ControllerIncrement* ControllerIncrement();
+  //! Redefine vtkInteractorStyle::OnKeyDown
+  virtual void OnKeyDown();
+
+  //! Provide instructions for Picking
+  void ActionPicking();
+
+  //! To set current OnKeyDown controller 
+  void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*);
+
+  //! To get current OnKeyDown controller 
+  SVTK_ControllerOnKeyDown* ControllerOnKeyDown();
   
-  void                     IncrementalPan   ( const int incrX, const int incrY );
-  void                     IncrementalZoom  ( const int incr );
-  void                     IncrementalRotate( const int incrX, const int incrY );
+  SVTK_Selector* GetSelector();
 
  protected:
   SVTK_InteractorStyle();
   ~SVTK_InteractorStyle();
-  SVTK_InteractorStyle(const SVTK_InteractorStyle&) {};
-  void operator=(const SVTK_InteractorStyle&) {};
 
-  SVTK_Selector* GetSelector();
+  QWidget*
+  GetRenderWidget();
+  
+  // Generic event bindings must be overridden in subclasses
+  virtual void OnMouseMove  (int ctrl, int shift, int x, int y);
+  virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
+  virtual void OnLeftButtonUp  (int ctrl, int shift, int x, int y);
+  virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y);
+  virtual void OnMiddleButtonUp  (int ctrl, int shift, int x, int y);
+  virtual void OnRightButtonDown(int ctrl, int shift, int x, int y);
+  virtual void OnRightButtonUp  (int ctrl, int shift, int x, int y);
 
   void RotateXY(int dx, int dy);
   void PanXY(int x, int y, int oldX, int oldY);
@@ -126,47 +246,50 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject,
   void fitRect(const int left, const int top, const int right, const int bottom);
   void Place(const int theX, const int theY);
   void TranslateView(int toX, int toY, int fromX, int fromY);
-  bool IsInRect(vtkActor* theActor, 
-               const int left, const int top, 
-               const int right, const int bottom);
-  bool IsInRect(vtkCell* theCell, 
-               const int left, const int top, 
-               const int right, const int bottom);
-  bool IsInRect(float* thePoint, 
-               const int left, const int top, 
-               const int right, const int bottom);
+
+  void
+  IncrementalPan( const int incrX, const int incrY );
+
+  void
+  IncrementalZoom( const int incr );
+
+  void
+  IncrementalRotate( const int incrX, const int incrY );
+
+  // Main process event method (reimplemented from #vtkInteractorStyle)
+  static 
+  void
+  ProcessEvents(vtkObject* object, 
+               unsigned long event,
+               void* clientData, 
+               void* callData );
 
   float MotionFactor;
   float RadianToDegree;                 // constant: for conv from deg to rad
   double myScale;
 
-  SALOME_Actor* myPreViewActor;
-
-  SVTK_Actor* myPreSelectionActor;
-  SALOME_Actor* mySelectedActor;
-  int myElemId;
-  int myEdgeId;
-  int myNodeId;
-
- public:
-  bool eventFilter(QObject* object, QEvent* event);
+ protected:
   void startZoom();
   void startPan();
   void startGlobalPan();
   void startRotate();
   void startFitArea();
   void startSpin();
-  bool needsRedrawing();
 
  protected:
   void loadCursors();
   void startOperation(int operation);
   void onStartOperation();
-  void onFinishOperation();
+  virtual void onFinishOperation();
   void onOperation(QPoint mousePos);
   void onCursorMove(QPoint mousePos);
   void setCursor(const int operation);
 
+  void onSpaceMouseMove( double* data );
+  virtual void onSpaceMouseButton( int button );
+
+  void DominantCombinedSwitch();
+  
  protected:
   QCursor                   myDefCursor;
   QCursor                   myPanCursor;
@@ -180,18 +303,26 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject,
   bool                      myCursorState;
   bool                      myShiftState;
   int                       ForcedState;
+
+  vtkSmartPointer<SALOME_Actor> myLastHighlitedActor;
+  vtkSmartPointer<SALOME_Actor> myLastPreHighlitedActor;
+
+  //! "Increment" controller for pan/rotate/zoom operations
+  vtkSmartPointer<SVTK_ControllerIncrement> myControllerIncrement;
+
+  //!controls the behaviour of KeyDown event in SALOME way
+  vtkSmartPointer<SVTK_ControllerOnKeyDown> myControllerOnKeyDown;
+
+  // SpaceMouse short cuts
+  int                       mySMDecreaseSpeedBtn;
+  int                       mySMIncreaseSpeedBtn;
+  int                       mySMDominantCombinedSwitchBtn;
   
-  SVTK_RenderWindowInteractor* myInteractor;
-  SVTK_ViewWindow*          myViewWindow;
-  //merge with V2_2_0_VISU_improvements:VTKViewer_Trihedron*      myTrihedron;
-  QWidget*                  myGUIWindow;
-  
-  std::map<int, Handle(VTKViewer_Filter)> myFilters;
+  vtkSmartPointer<SVTK_GenericRenderWindowInteractor> myInteractor;
+
+  PSelectionEvent mySelectionEvent;
 
-  //  members from old version
-  double                    DeltaElevation;
-  double                    DeltaAzimuth;
-  int                       LastPos[2];
+  vtkSmartPointer<vtkPicker> myPicker;
 };
 
 #endif
diff --git a/src/SVTK/SVTK_MainWindow.cxx b/src/SVTK/SVTK_MainWindow.cxx
new file mode 100644 (file)
index 0000000..ad01609
--- /dev/null
@@ -0,0 +1,701 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#include "SALOME_Actor.h"
+
+#include <vtkGenericRenderWindowInteractor.h>
+#include <vtkRenderer.h>
+
+#include "QtxAction.h"
+
+#include "SUIT_ToolButton.h"
+#include "SUIT_MessageBox.h"
+#include "SUIT_ViewWindow.h"
+
+#include "SUIT_Tools.h"
+#include "SUIT_ResourceMgr.h"
+#include "SVTK_NonIsometricDlg.h"
+#include "SVTK_CubeAxesDlg.h"
+
+#include "SVTK_MainWindow.h"
+#include "SVTK_Event.h"
+#include "SVTK_Renderer.h"
+#include "SVTK_RenderWindowInteractor.h"
+
+#include "SVTK_Selector.h"
+
+#include <qimage.h>
+
+
+//----------------------------------------------------------------------------
+SVTK_MainWindow
+::SVTK_MainWindow(QWidget* theParent, 
+                 const char* theName,
+                 SUIT_ResourceMgr* theResourceMgr,
+                 SUIT_ViewWindow* theViewWindow) :
+  QMainWindow(theParent,theName,0),
+  myViewWindow(theViewWindow)
+{
+  myToolBar = new QToolBar(this);
+  myToolBar->setCloseMode(QDockWindow::Undocked);
+  myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
+
+  createActions(theResourceMgr);
+  createToolBar();
+}
+
+void
+SVTK_MainWindow
+::Initialize(SVTK_RenderWindowInteractor* theInteractor)
+{
+  myInteractor = theInteractor;
+  SetEventDispatcher(myInteractor->GetDevice());
+
+  setCentralWidget(myInteractor);
+  myInteractor->setBackgroundMode(Qt::NoBackground);
+
+  myInteractor->setFocusPolicy(StrongFocus);
+  myInteractor->setFocus();
+  setFocusProxy(myInteractor);
+}
+
+
+//----------------------------------------------------------------------------
+SVTK_MainWindow
+::~SVTK_MainWindow()
+{
+}
+
+
+//----------------------------------------------------------------------------
+SVTK_RenderWindowInteractor*
+SVTK_MainWindow
+::GetInteractor()
+{
+  return myInteractor;
+}
+
+vtkRenderWindowInteractor*
+SVTK_MainWindow
+::getInteractor()
+{
+  return GetInteractor()->GetDevice();
+}
+
+vtkRenderWindow*
+SVTK_MainWindow
+::getRenderWindow()
+{
+  return GetInteractor()->getRenderWindow();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::Repaint(bool theUpdateTrihedron)
+{
+  if(theUpdateTrihedron) 
+    GetRenderer()->OnAdjustTrihedron();
+
+  GetInteractor()->update();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::InvokeEvent(unsigned long theEvent, void* theCallData)
+{
+  GetInteractor()->InvokeEvent(theEvent,theCallData);
+}
+
+//----------------------------------------------------------------------------
+vtkInteractorStyle*
+SVTK_MainWindow
+::GetInteractorStyle()
+{
+  return GetInteractor()->GetInteractorStyle();
+}
+
+void
+SVTK_MainWindow
+::PushInteractorStyle(vtkInteractorStyle* theStyle)
+{
+  GetInteractor()->PushInteractorStyle(theStyle);
+}
+
+void
+SVTK_MainWindow
+::PopInteractorStyle()
+{
+  GetInteractor()->PopInteractorStyle();
+}
+
+//----------------------------------------------------------------------------
+SVTK_Selector*
+SVTK_MainWindow
+::GetSelector()
+{
+  return GetInteractor()->GetSelector();
+}
+
+Selection_Mode
+SVTK_MainWindow
+::SelectionMode()
+{
+  return GetSelector()->SelectionMode();
+}
+
+void
+SVTK_MainWindow
+::SetSelectionMode(Selection_Mode theMode)
+{
+  GetSelector()->SetSelectionMode(theMode);
+}
+
+
+//----------------------------------------------------------------------------
+SVTK_Renderer* 
+SVTK_MainWindow
+::GetRenderer()
+{
+  return GetInteractor()->GetRenderer();
+}
+
+vtkRenderer* 
+SVTK_MainWindow
+::getRenderer()
+{
+  return GetInteractor()->getRenderer();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::SetBackgroundColor(const QColor& theColor)
+{
+  getRenderer()->SetBackground(theColor.red()/255.0, 
+                              theColor.green()/255.0,
+                              theColor.blue()/255.0);
+}
+
+QColor
+SVTK_MainWindow
+::BackgroundColor()
+{
+  float aBackgroundColor[3];
+  getRenderer()->GetBackground(aBackgroundColor);
+  return QColor(int(aBackgroundColor[0]*255), 
+               int(aBackgroundColor[1]*255), 
+               int(aBackgroundColor[2]*255));
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::GetScale( double theScale[3] ) 
+{
+  GetRenderer()->GetScale( theScale );
+}
+
+void
+SVTK_MainWindow
+::SetScale( double theScale[3] ) 
+{
+  GetRenderer()->SetScale( theScale );
+  Repaint();
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::AddActor(VTKViewer_Actor* theActor, 
+          bool theIsUpdate)
+{
+  GetRenderer()->AddActor(theActor);
+  if(theIsUpdate) 
+    Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::RemoveActor(VTKViewer_Actor* theActor, 
+             bool theIsUpdate)
+{
+  GetRenderer()->RemoveActor(theActor);
+  if(theIsUpdate) 
+    Repaint();
+}
+
+
+//----------------------------------------------------------------------------
+int
+SVTK_MainWindow
+::GetTrihedronSize()
+{
+  return GetRenderer()->GetTrihedronSize();
+}
+
+//----------------------------------------------------------------------------
+void 
+SVTK_MainWindow
+::SetTrihedronSize( const int theSize )
+{
+  GetRenderer()->SetTrihedronSize(theSize);
+  Repaint();
+}
+
+
+//----------------------------------------------------------------------------
+/*! If parameter theIsForcedUpdate is true, recalculate parameters for
+ *  trihedron and cube axes, even if trihedron and cube axes is invisible.
+ */
+void
+SVTK_MainWindow
+::AdjustActors()
+{
+  GetRenderer()->AdjustActors();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+bool
+SVTK_MainWindow
+::IsTrihedronDisplayed()
+{
+  return GetRenderer()->IsTrihedronDisplayed();
+}
+
+//----------------------------------------------------------------------------
+bool
+SVTK_MainWindow
+::IsCubeAxesDisplayed()
+{
+  return GetRenderer()->IsCubeAxesDisplayed();
+}
+
+//----------------------------------------------------------------------------
+VTKViewer_Trihedron*  
+SVTK_MainWindow
+::GetTrihedron() 
+{ 
+  return GetRenderer()->GetTrihedron(); 
+}
+
+//----------------------------------------------------------------------------
+SVTK_CubeAxesActor2D* 
+SVTK_MainWindow
+::GetCubeAxes() 
+{ 
+  return GetRenderer()->GetCubeAxes(); 
+}
+
+
+//----------------------------------------------------------------------------
+QToolBar* 
+SVTK_MainWindow
+::getToolBar()
+{
+  return myToolBar;
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::SetEventDispatcher(vtkObject* theDispatcher)
+{
+  myEventDispatcher = theDispatcher;
+}
+
+//----------------------------------------------------------------------------
+#if defined(WIN32) && !defined(_DEBUG)
+#pragma optimize( "", off )
+#endif
+
+void
+SVTK_MainWindow
+::createActions(SUIT_ResourceMgr* theResourceMgr)
+{
+  if(!myActionsMap.isEmpty()) 
+    return;
+  
+  QtxAction* anAction;
+
+  // Dump view
+  anAction = new QtxAction(tr("MNU_DUMP_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
+                          tr( "MNU_DUMP_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
+  connect(anAction, SIGNAL(activated()), myViewWindow, SLOT(onDumpView()));
+  myActionsMap[ DumpId ] = anAction;
+
+  // FitAll
+  anAction = new QtxAction(tr("MNU_FITALL"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
+                          tr( "MNU_FITALL" ), 0, this);
+  anAction->setStatusTip(tr("DSC_FITALL"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
+  myActionsMap[ FitAllId ] = anAction;
+
+  // FitRect
+  anAction = new QtxAction(tr("MNU_FITRECT"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
+                          tr( "MNU_FITRECT" ), 0, this);
+  anAction->setStatusTip(tr("DSC_FITRECT"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
+  myActionsMap[ FitRectId ] = anAction;
+
+  // Zoom
+  anAction = new QtxAction(tr("MNU_ZOOM_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
+                          tr( "MNU_ZOOM_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
+  myActionsMap[ ZoomId ] = anAction;
+
+  // Panning
+  anAction = new QtxAction(tr("MNU_PAN_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
+                          tr( "MNU_PAN_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_PAN_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
+  myActionsMap[ PanId ] = anAction;
+
+  // Global Panning
+  anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
+                          tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
+  myActionsMap[ GlobalPanId ] = anAction;
+
+  // Rotation
+  anAction = new QtxAction(tr("MNU_ROTATE_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
+                          tr( "MNU_ROTATE_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
+  myActionsMap[ RotationId ] = anAction;
+
+  // Projections
+  anAction = new QtxAction(tr("MNU_FRONT_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
+                          tr( "MNU_FRONT_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
+  myActionsMap[ FrontId ] = anAction;
+
+  anAction = new QtxAction(tr("MNU_BACK_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
+                          tr( "MNU_BACK_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_BACK_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
+  myActionsMap[ BackId ] = anAction;
+
+  anAction = new QtxAction(tr("MNU_TOP_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
+                          tr( "MNU_TOP_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_TOP_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
+  myActionsMap[ TopId ] = anAction;
+
+  anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
+                          tr( "MNU_BOTTOM_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
+  myActionsMap[ BottomId ] = anAction;
+
+  anAction = new QtxAction(tr("MNU_LEFT_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
+                          tr( "MNU_LEFT_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
+  myActionsMap[ LeftId ] = anAction;
+
+  anAction = new QtxAction(tr("MNU_RIGHT_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
+                          tr( "MNU_RIGHT_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
+  myActionsMap[ RightId ] = anAction;
+
+  // Reset
+  anAction = new QtxAction(tr("MNU_RESET_VIEW"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
+                          tr( "MNU_RESET_VIEW" ), 0, this);
+  anAction->setStatusTip(tr("DSC_RESET_VIEW"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
+  myActionsMap[ ResetId ] = anAction;
+
+  // onViewTrihedron: Shows - Hides Trihedron
+  anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
+                          tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
+  anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
+  connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
+  myActionsMap[ ViewTrihedronId ] = anAction;
+
+  // onNonIsometric: Manage non-isometric params
+  anAction = new QtxAction(tr("MNU_SVTK_SCALING"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
+                          tr( "MNU_SVTK_SCALING" ), 0, this);
+  anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
+  anAction->setToggleAction(true);
+  connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
+  myActionsMap[ NonIsometric ] = anAction;
+
+  myNonIsometricDlg = new SVTK_NonIsometricDlg(this,"SVTK_NonIsometricDlg",anAction);
+
+  // onGraduatedAxes: Manage graduated axes params
+  anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"), 
+                          theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_GRADUATED_AXES" ) ),
+                          tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
+  anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
+  anAction->setToggleAction(true);
+  connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
+  myActionsMap[ GraduatedAxes ] = anAction;
+
+  myCubeAxesDlg = new SVTK_CubeAxesDlg(this,"SVTK_CubeAxesDlg",anAction);
+}
+
+#if defined(WIN32) && !defined(_DEBUG)
+#pragma optimize( "", on )
+#endif
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::createToolBar()
+{
+  myActionsMap[DumpId]->addTo(myToolBar);
+  myActionsMap[ViewTrihedronId]->addTo(myToolBar);
+
+  SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
+  aScaleBtn->AddAction(myActionsMap[FitAllId]);
+  aScaleBtn->AddAction(myActionsMap[FitRectId]);
+  aScaleBtn->AddAction(myActionsMap[ZoomId]);
+
+  SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
+  aPanningBtn->AddAction(myActionsMap[PanId]);
+  aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
+
+  myActionsMap[RotationId]->addTo(myToolBar);
+
+  SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
+  aViewsBtn->AddAction(myActionsMap[FrontId]);
+  aViewsBtn->AddAction(myActionsMap[BackId]);
+  aViewsBtn->AddAction(myActionsMap[TopId]);
+  aViewsBtn->AddAction(myActionsMap[BottomId]);
+  aViewsBtn->AddAction(myActionsMap[LeftId]);
+  aViewsBtn->AddAction(myActionsMap[RightId]);
+
+  myActionsMap[ResetId]->addTo(myToolBar);
+
+  myActionsMap[NonIsometric]->addTo(myToolBar);
+  myActionsMap[GraduatedAxes]->addTo(myToolBar);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::activateZoom()
+{
+  myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::activatePanning()
+{
+  myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::activateRotation()
+{
+  myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::activateGlobalPanning()
+{
+  myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::activateWindowFit()
+{
+  myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onFrontView()
+{
+  GetRenderer()->OnFrontView();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onBackView()
+{
+  GetRenderer()->OnBackView();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onTopView()
+{
+  GetRenderer()->OnTopView();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onBottomView()
+{
+  GetRenderer()->OnBottomView();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onLeftView()
+{
+  GetRenderer()->OnLeftView();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onRightView()
+{
+  GetRenderer()->OnRightView();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onResetView()
+{
+  GetRenderer()->OnResetView();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onFitAll()
+{
+  GetRenderer()->OnFitAll();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void 
+SVTK_MainWindow
+::onViewTrihedron()
+{
+  GetRenderer()->OnViewTrihedron();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onViewCubeAxes()
+{
+  GetRenderer()->OnViewCubeAxes();
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onNonIsometric(bool theIsActivate)
+{
+  if(theIsActivate){
+    myNonIsometricDlg->Update();
+    myNonIsometricDlg->show();
+  }else
+    myNonIsometricDlg->hide();
+}
+
+void
+SVTK_MainWindow
+::onGraduatedAxes(bool theIsActivate)
+{
+  if(theIsActivate){
+    myCubeAxesDlg->Update();
+    myCubeAxesDlg->show();
+  }else
+    myCubeAxesDlg->hide();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onAdjustTrihedron()
+{   
+  GetRenderer()->OnAdjustTrihedron();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_MainWindow
+::onAdjustCubeAxes()
+{   
+  GetRenderer()->OnAdjustCubeAxes();
+}
+
+//----------------------------------------------------------------------------
+QImage
+SVTK_MainWindow
+::dumpView()
+{
+  QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() );
+  return px.convertToImage();
+}
diff --git a/src/SVTK/SVTK_MainWindow.h b/src/SVTK/SVTK_MainWindow.h
new file mode 100644 (file)
index 0000000..7580937
--- /dev/null
@@ -0,0 +1,238 @@
+#ifndef SVTK_MAINWINDOW_H
+#define SVTK_MAINWINDOW_H
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+#include "SVTK.h"
+#include "SVTK_Selection.h"
+
+#include <vtkSmartPointer.h>
+
+#include <qmainwindow.h>
+
+class QtxAction;
+
+class vtkObject;
+class vtkRenderer;
+class vtkRenderWindow;
+class vtkInteractorStyle;
+class vtkRenderWindowInteractor;
+
+class SUIT_ResourceMgr;
+class SUIT_ViewWindow;
+
+class SVTK_RenderWindowInteractor;
+class SVTK_NonIsometricDlg;
+class SVTK_CubeAxesActor2D;
+class SVTK_CubeAxesDlg;
+
+class VTKViewer_Trihedron;
+class VTKViewer_Transform;
+class VTKViewer_Actor;
+
+class SVTK_Renderer;
+class SVTK_Selector;
+
+
+//----------------------------------------------------------------------------
+//! The class is a container for #SVTK_RenderWindowInteractor.
+/*!
+  The class contains #SVTK_RenderWindowInteractor instance and
+  adds predefined viewer actions and toolbar for user interaction.
+*/
+class SVTK_EXPORT SVTK_MainWindow: public QMainWindow
+{
+  Q_OBJECT;
+
+public:
+  SVTK_MainWindow(QWidget* theParent, 
+                 const char* theName,
+                 SUIT_ResourceMgr* theResourceMgr,
+                 SUIT_ViewWindow* theViewWindow);
+  
+  //! To initialize the class
+  virtual
+  void
+  Initialize(SVTK_RenderWindowInteractor* theInteractor);
+
+  virtual
+  ~SVTK_MainWindow();
+
+  //----------------------------------------------------------------------------
+  //! Get used #SVTK_RenderWindowInteractor
+  SVTK_RenderWindowInteractor*
+  GetInteractor();
+
+  //! Get used #vtkRenderWindowInteractor (obsolete)
+  vtkRenderWindowInteractor*
+  getInteractor();
+
+  //! Get used #vtkRenderWindow (obsolete)
+  vtkRenderWindow*
+  getRenderWindow();
+
+  //! To repaint the view
+  void
+  Repaint(bool theUpdateTrihedron = true);
+
+  //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance
+  void
+  InvokeEvent(unsigned long theEvent, void* theCallData);
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_RenderWindowInteractor::GetInteractorStyle
+  vtkInteractorStyle* 
+  GetInteractorStyle();
+
+  //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle
+  void
+  PushInteractorStyle(vtkInteractorStyle* theStyle);
+
+  //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle
+  void
+  PopInteractorStyle();
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_RenderWindowInteractor::GetSelector
+  SVTK_Selector* 
+  GetSelector();
+
+  //! Redirect the request to #SVTK_RenderWindowInteractor::SelectionMode
+  Selection_Mode
+  SelectionMode();
+
+  //! Redirect the request to #SVTK_RenderWindowInteractor::SetSelectionMode
+  void 
+  SetSelectionMode(Selection_Mode theMode);
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_RenderWindowInteractor::GetRenderer
+  SVTK_Renderer* 
+  GetRenderer();
+
+  //! Redirect the request to #SVTK_RenderWindowInteractor::getRenderer
+  vtkRenderer* 
+  getRenderer();
+
+  //! Set background color to the view
+  void
+  SetBackgroundColor(const QColor& theColor);
+
+  //! Get background color of the view
+  QColor 
+  BackgroundColor();
+
+  //! Redirect the request to #SVTK_Renderer::SetScale
+  void
+  SetScale(double theScale[3]);
+
+  //! Redirect the request to #SVTK_Renderer::GetScale
+  void
+  GetScale(double theScale[3]);
+
+  //! Redirect the request to #SVTK_Renderer::AddActor
+  virtual
+  void 
+  AddActor(VTKViewer_Actor* theActor, 
+          bool theIsUpdate = false);
+
+  //! Redirect the request to #SVTK_Renderer::RemoveActor
+  virtual
+  void 
+  RemoveActor(VTKViewer_Actor* theActor, 
+             bool theIsUpdate = false);
+
+  //! Redirect the request to #SVTK_Renderer::GetTrihedronSize
+  int  
+  GetTrihedronSize();
+
+  //! Redirect the request to #SVTK_Renderer::SetTrihedronSize
+  void
+  SetTrihedronSize(const int theSize);
+
+  //! Redirect the request to #SVTK_Renderer::AdjustActors
+  void 
+  AdjustActors();
+
+  //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
+  bool
+  IsTrihedronDisplayed();
+  //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
+  bool
+  IsCubeAxesDisplayed();
+
+  //! Redirect the request to #SVTK_Renderer::GetTrihedron
+  VTKViewer_Trihedron* 
+  GetTrihedron();
+
+  //! Redirect the request to #SVTK_Renderer::GetCubeAxes
+  SVTK_CubeAxesActor2D*
+  GetCubeAxes();
+
+  //----------------------------------------------------------------------------
+  QToolBar* getToolBar();
+
+ public slots:
+  void activateZoom();
+  void activateWindowFit();
+  void activateRotation();
+  void activatePanning(); 
+  void activateGlobalPanning(); 
+
+  void onFrontView(); 
+  void onBackView(); 
+  void onTopView();
+  void onBottomView();
+  void onRightView(); 
+  void onLeftView();     
+
+  void onResetView();     
+  void onFitAll();
+
+  void onViewTrihedron(); 
+  void onViewCubeAxes();
+
+  void onNonIsometric(bool theIsActivate);
+  void onGraduatedAxes(bool theIsActivate);
+
+  void onAdjustTrihedron();
+  void onAdjustCubeAxes();
+
+ public:
+  QImage dumpView();
+
+ protected:  
+  void
+  createActions(SUIT_ResourceMgr* theResourceMgr);
+
+  void
+  createToolBar();
+
+  void
+  SetEventDispatcher(vtkObject* theDispatcher);
+
+  enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId,
+         FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, 
+        ViewTrihedronId, NonIsometric, GraduatedAxes};
+  typedef QMap<int, QtxAction*> TActionsMap;
+
+  SUIT_ViewWindow* myViewWindow;
+
+  SVTK_NonIsometricDlg* myNonIsometricDlg;
+  SVTK_CubeAxesDlg* myCubeAxesDlg;
+
+  vtkSmartPointer<vtkObject> myEventDispatcher;
+  TActionsMap myActionsMap;  
+  QToolBar* myToolBar;
+
+  SVTK_RenderWindowInteractor* myInteractor;
+};
+
+#ifdef WIN32
+#pragma warning( default:4251 )
+#endif
+
+#endif
diff --git a/src/SVTK/SVTK_NonIsometricDlg.cxx b/src/SVTK/SVTK_NonIsometricDlg.cxx
new file mode 100644 (file)
index 0000000..a01bcbd
--- /dev/null
@@ -0,0 +1,200 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#include "SVTK_NonIsometricDlg.h"
+#include "SVTK_MainWindow.h"
+#include "SVTK_Renderer.h"
+
+#include "QtxDblSpinBox.h"
+#include "QtxAction.h"
+
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qpushbutton.h>
+#include <qlayout.h>
+
+using namespace std;
+
+/*!
+  Constructor
+*/
+SVTK_NonIsometricDlg
+::SVTK_NonIsometricDlg(SVTK_MainWindow* theParent,
+                      const char* theName,
+                      QtxAction* theAction):
+  QDialog(theParent, 
+         theName, 
+         false, 
+         WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
+  m_MainWindow(theParent),
+  m_Action(theAction)
+{
+  setCaption(tr("DLG_TITLE"));
+  setSizeGripEnabled(TRUE);
+
+  // Create layout for this dialog
+  QGridLayout* layoutDlg = new QGridLayout (this);
+  layoutDlg->setSpacing(6);
+  layoutDlg->setMargin(11);
+
+  // Create croup box with grid layout
+  QGroupBox* GroupBox = new QGroupBox(this, "GroupBox");
+  QGridLayout* glGroupBox = new QGridLayout(GroupBox);
+  glGroupBox->setMargin(11);
+  glGroupBox->setSpacing(6);
+
+  // "X" scaling
+  QLabel* TextLabelX = new QLabel (tr("LBL_X"), GroupBox, "TextLabelX");
+  m_sbXcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox);
+  m_sbXcoeff->setMinimumWidth(80);
+  m_sbXcoeff->setValue(1.0);
+
+  // "Y" scaling
+  QLabel* TextLabelY = new QLabel (tr("LBL_Y"), GroupBox, "TextLabelY");
+  m_sbYcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox);
+  m_sbYcoeff->setMinimumWidth(80);
+  m_sbYcoeff->setValue(1.0);
+
+  // "Z" scaling
+  QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), GroupBox, "TextLabelZ");
+  m_sbZcoeff = new QtxDblSpinBox(-VTK_LARGE_FLOAT, VTK_LARGE_FLOAT, 0.1, GroupBox);
+  m_sbZcoeff->setMinimumWidth(80);
+  m_sbZcoeff->setValue(1.0);
+
+  // Create <Reset> button
+  m_bReset = new QPushButton(tr("&Reset"), GroupBox, "m_bReset");
+
+  // Layout widgets in the group box
+  glGroupBox->addWidget(TextLabelX, 0, 0);
+  glGroupBox->addWidget(m_sbXcoeff, 0, 1);
+  glGroupBox->addWidget(TextLabelY, 0, 2);
+  glGroupBox->addWidget(m_sbYcoeff, 0, 3);
+  glGroupBox->addWidget(TextLabelZ, 0, 4);
+  glGroupBox->addWidget(m_sbZcoeff, 0, 5);
+  glGroupBox->addWidget(m_bReset,   0, 6);
+
+  // OK, CANCEL, Apply button
+  QGroupBox* aWgt = new QGroupBox(this);
+  QHBoxLayout* aHBoxLayout = new QHBoxLayout(aWgt);
+  aHBoxLayout->setMargin(11);
+  aHBoxLayout->setSpacing(6);
+  // Create <OK> button
+  QPushButton* m_bOk = new QPushButton(tr("O&K"), aWgt, "m_bOk");
+  m_bOk->setDefault(TRUE);
+  m_bOk->setAutoDefault(TRUE);
+  // Create <Apply> button
+  QPushButton* m_bApply = new QPushButton(tr("&Apply"), aWgt, "m_bApply");
+  m_bApply->setAutoDefault(TRUE);
+  // Create <Cancel> button
+  QPushButton* m_bCancel = new QPushButton(tr("&Cancel"), aWgt, "m_bCancel");
+  m_bCancel->setAutoDefault(TRUE);
+
+  // Layout buttons
+  aHBoxLayout->addWidget(m_bOk);
+  aHBoxLayout->addWidget(m_bApply);
+  aHBoxLayout->addStretch();
+  aHBoxLayout->addWidget(m_bCancel);
+
+  // Layout top level widgets
+  layoutDlg->addWidget(GroupBox,0,0);
+  layoutDlg->addWidget(aWgt,1,0);
+
+  // signals and slots connections
+  connect(m_bCancel, SIGNAL(clicked()), this, SLOT(onClickClose()));
+  connect(m_bOk,     SIGNAL(clicked()), this, SLOT(onClickOk()));
+  connect(m_bApply,  SIGNAL(clicked()), this, SLOT(onClickApply()));
+  connect(m_bReset,  SIGNAL(clicked()), this, SLOT(onClickReset()));
+
+  this->resize(100, this->sizeHint().height());
+}
+
+/*
+ *  Destroys the object and frees any allocated resources
+ */
+SVTK_NonIsometricDlg
+::~SVTK_NonIsometricDlg()
+{
+  // no need to delete child widgets, Qt does it all for us
+}
+
+void 
+SVTK_NonIsometricDlg
+::Update()
+{
+  // Get values from the VTK view
+  double aScaleFactor[3];
+  m_MainWindow->GetScale(aScaleFactor);
+  m_sbXcoeff->setValue(aScaleFactor[0]);
+  m_sbYcoeff->setValue(aScaleFactor[1]);
+  m_sbZcoeff->setValue(aScaleFactor[2]);
+}
+
+void 
+SVTK_NonIsometricDlg
+::onClickOk()
+{
+  //apply changes
+  onClickApply();
+  //Close dialog
+  accept();
+}
+
+void
+SVTK_NonIsometricDlg
+::onClickApply()
+{
+  double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
+  m_MainWindow->SetScale(aScale);
+}
+
+void
+SVTK_NonIsometricDlg
+::onClickReset()
+{
+  m_bReset->setFocus();
+  m_sbXcoeff->setValue(1.0);
+  m_sbYcoeff->setValue(1.0);
+  m_sbZcoeff->setValue(1.0);
+}
+
+void 
+SVTK_NonIsometricDlg
+::onClickClose()
+{
+  reject();
+
+  m_Action->setOn( false );
+}
+
+void 
+SVTK_NonIsometricDlg
+::done( int r )
+{
+  m_Action->setOn( false );
+  QDialog::done( r );
+}
diff --git a/src/SVTK/SVTK_NonIsometricDlg.h b/src/SVTK/SVTK_NonIsometricDlg.h
new file mode 100644 (file)
index 0000000..6a11a14
--- /dev/null
@@ -0,0 +1,73 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#ifndef SVTK_NONISOMETRICDLG_H
+#define SVTK_NONISOMETRICDLG_H
+
+#include <qdialog.h>
+
+class SVTK_MainWindow;
+
+class QtxDblSpinBox;
+class QtxAction;
+
+class QPushButton;
+
+
+class SVTK_NonIsometricDlg : public QDialog
+{
+  Q_OBJECT;
+
+public:
+  SVTK_NonIsometricDlg(SVTK_MainWindow* theParent,
+                      const char* theName,
+                      QtxAction* theAction);
+
+  ~SVTK_NonIsometricDlg();
+
+  void Update();
+
+protected:
+  SVTK_MainWindow *m_MainWindow;
+  QtxAction* m_Action;
+
+  QtxDblSpinBox* m_sbXcoeff;
+  QtxDblSpinBox* m_sbYcoeff;
+  QtxDblSpinBox* m_sbZcoeff;
+  QPushButton* m_bReset;
+
+protected slots:
+  void onClickApply();
+  void onClickReset();
+  void onClickOk();
+  void onClickClose();
+
+  virtual void done( int );
+};
+
+#endif // SVTK_NONISOMETRICDLG_H
diff --git a/src/SVTK/SVTK_RectPicker.cxx b/src/SVTK/SVTK_RectPicker.cxx
new file mode 100644 (file)
index 0000000..775782e
--- /dev/null
@@ -0,0 +1,489 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SVTK_RectPicker.cxx
+//  Author : 
+//  Module : SALOME
+
+#include "SVTK_RectPicker.h"
+
+#include <set>
+
+#include <vtkObjectFactory.h>
+#include <vtkCommand.h>
+
+#include <vtkAbstractMapper3D.h>
+#include <vtkMapper.h>
+#include <vtkProperty.h>
+
+#include <vtkAssemblyPath.h>
+#include <vtkAssemblyNode.h>
+
+#include <vtkRenderWindow.h>
+#include <vtkMatrix4x4.h>
+#include <vtkRenderer.h>
+#include <vtkDataSet.h>
+#include <vtkPoints.h>
+#include <vtkCamera.h>
+#include <vtkCell.h>
+
+//----------------------------------------------------------------------------
+namespace
+{
+  //----------------------------------------------------------------------------
+  inline
+  float
+  GetZ(float* theZPtr,
+       int theSelection[4],
+       int theDX,
+       int theDY)
+  {
+    return theZPtr[theDX - theSelection[0] + (theDY - theSelection[1])*(theSelection[2] - theSelection[0] + 1)];
+  }
+
+
+  //----------------------------------------------------------------------------
+  inline
+  int
+  Check(float* theZPtr,
+       int theSelection[4],
+       float theTolerance,
+       float theDZ,
+       int theDX,
+       int theDY)
+  {
+    int aRet = 0;
+    float aZ = -1.0;
+    if(theDX >= theSelection[0] && theDX <= theSelection[2] &&
+       theDY >= theSelection[1] && theDY <= theSelection[3])
+    {
+      // Access the value from the captured zbuffer.  Note, we only
+      // captured a portion of the zbuffer, so we need to offset dx by
+      // the selection window.
+      aZ = GetZ(theZPtr,theSelection,theDX,theDY);
+      if(aZ > theTolerance && aZ < 1.0 - theTolerance){
+       aRet = fabs(aZ - theDZ) <= theTolerance;
+      }
+    }
+
+    //cout<<"\tCheck = {"<<theDX<<", "<<theDY<<", "<<theDZ<<", "<<aZ<<"} = "<<aRet<<"\n";
+    return aRet;
+  }
+
+
+  //----------------------------------------------------------------------------
+  void
+  SelectVisiblePoints(int theSelection[4],
+                     vtkRenderer *theRenderer,
+                     vtkDataSet *theInput,
+                     SVTK_RectPicker::TVectorIds& theVisibleIds,
+                     SVTK_RectPicker::TVectorIds& theInVisibleIds,
+                     float theTolerance)
+  {
+    theVisibleIds.clear();
+    theInVisibleIds.clear();
+
+    vtkIdType aNumPts = theInput->GetNumberOfPoints();
+    if(aNumPts < 1)
+      return;
+    
+    theVisibleIds.reserve(aNumPts/2 + 1);
+    theInVisibleIds.reserve(aNumPts/2 + 1);
+
+    // Grab the composite perspective transform.  This matrix is used to convert
+    // each point to view coordinates.  vtkRenderer provides a WorldToView()
+    // method but it computes the composite perspective transform each time
+    // WorldToView() is called.  This is expensive, so we get the matrix once
+    // and handle the transformation ourselves.
+    vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
+    aMatrix->DeepCopy(theRenderer->GetActiveCamera()->
+                     GetCompositePerspectiveTransformMatrix(1,0,1));
+
+    // We grab the z-buffer for the selection region all at once and probe the resulting array.
+    float *aZPtr = theRenderer->GetRenderWindow()->
+      GetZbufferData(theSelection[0], theSelection[1], theSelection[2], theSelection[3]);
+
+    //cout<<"theSelection = {"<<theSelection[0]<<", "<<theSelection[1]<<", "<<theSelection[2]<<", "<<theSelection[3]<<"}\n";
+    /*
+    for(int iY = theSelection[1]; iY <= theSelection[3];  iY++){
+      for(int iX = theSelection[0]; iX <= theSelection[2];  iX++){
+       cout<<GetZ(aZPtr,theSelection,iX,iY)<<" ";
+      }
+      cout<<endl;
+    }
+    */
+    for(vtkIdType aPntId = 0; aPntId < aNumPts; aPntId++){
+      // perform conversion
+      float aX[4] = {1.0, 1.0, 1.0, 1.0};
+      theInput->GetPoint(aPntId,aX);
+
+      float aView[4];
+      aMatrix->MultiplyPoint(aX,aView);
+      if(aView[3] == 0.0)
+       continue;
+      theRenderer->SetViewPoint(aView[0]/aView[3], 
+                               aView[1]/aView[3],
+                               aView[2]/aView[3]);
+      theRenderer->ViewToDisplay();
+
+      float aDX[3];
+      theRenderer->GetDisplayPoint(aDX);
+      
+      // check whether visible and in selection window 
+      if(aDX[0] >= theSelection[0] && aDX[0] <= theSelection[2] &&
+         aDX[1] >= theSelection[1] && aDX[1] <= theSelection[3])
+      {
+       //cout<<"aPntId "<<aPntId<<"; aDX = {"<<aDX[0]<<", "<<aDX[1]<<", "<<aDX[2]<<"}\n";
+       int aDX0 = int(aDX[0]);
+       int aDX1 = int(aDX[1]);
+
+       int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aDX0,aDX1);
+       if(aRet > 0)
+         goto ADD_VISIBLE;
+       if(aRet < 0)
+         goto ADD_INVISIBLE;
+
+       static int aMaxRadius = 5;
+       for(int aRadius = 1; aRadius < aMaxRadius; aRadius++){
+         int aStartDX[2] = {aDX0 - aRadius, aDX1 - aRadius};
+         for(int i = 0; i <= aRadius; i++){
+           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]++,aStartDX[1]);
+           if(aRet > 0)
+             goto ADD_VISIBLE;
+           if(aRet < 0)
+             goto ADD_INVISIBLE;
+         }
+         for(int i = 0; i <= aRadius; i++){
+           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]++);
+           if(aRet > 0)
+             goto ADD_VISIBLE;
+           if(aRet < 0)
+             goto ADD_INVISIBLE;
+         }
+         for(int i = 0; i <= aRadius; i++){
+           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0]--,aStartDX[1]);
+           if(aRet > 0)
+             goto ADD_VISIBLE;
+           if(aRet < 0)
+             goto ADD_INVISIBLE;
+         }
+         for(int i = 0; i <= aRadius; i++){
+           int aRet = Check(aZPtr,theSelection,theTolerance,aDX[2],aStartDX[0],aStartDX[1]--);
+           if(aRet > 0)
+             goto ADD_VISIBLE;
+           if(aRet < 0)
+             goto ADD_INVISIBLE;
+         }
+       }
+       if(false)
+         ADD_VISIBLE : theVisibleIds.push_back(aPntId);
+       if(false)
+         ADD_INVISIBLE : theInVisibleIds.push_back(aPntId);
+      }
+    }//for all points
+
+    aMatrix->Delete();
+
+    if(aZPtr)
+      delete [] aZPtr;
+  }
+
+
+  //----------------------------------------------------------------------------
+  inline
+  void
+  GetCenter(const float theBounds[6],
+           float theCenter[3])
+  {
+    theCenter[0] = (theBounds[1] + theBounds[0]) / 2.0;
+    theCenter[1] = (theBounds[3] + theBounds[2]) / 2.0;
+    theCenter[2] = (theBounds[5] + theBounds[4]) / 2.0;
+  }
+
+  void
+  SelectVisibleCells(int theSelection[4],
+                    vtkRenderer *theRenderer,
+                    vtkDataSet *theInput,
+                    SVTK_RectPicker::TVectorIds& theVectorIds,
+                    float theTolerance)
+  {
+    theVectorIds.clear();
+
+    vtkIdType aNumCells = theInput->GetNumberOfCells();
+    if(aNumCells < 1)
+      return;
+    
+    theVectorIds.reserve(aNumCells/2 + 1);
+
+    SVTK_RectPicker::TVectorIds aVisiblePntIds;
+    SVTK_RectPicker::TVectorIds anInVisiblePntIds;
+    SelectVisiblePoints(theSelection,
+                       theRenderer,
+                       theInput,
+                       aVisiblePntIds,
+                       anInVisiblePntIds,
+                       theTolerance);
+
+    typedef std::set<vtkIdType> TIdsSet;
+    TIdsSet aVisibleIds(aVisiblePntIds.begin(),aVisiblePntIds.end());
+    TIdsSet anInVisibleIds(anInVisiblePntIds.begin(),anInVisiblePntIds.end());
+
+    // Grab the composite perspective transform.  This matrix is used to convert
+    // each point to view coordinates.  vtkRenderer provides a WorldToView()
+    // method but it computes the composite perspective transform each time
+    // WorldToView() is called.  This is expensive, so we get the matrix once
+    // and handle the transformation ourselves.
+    vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
+    aMatrix->DeepCopy(theRenderer->GetActiveCamera()->
+                     GetCompositePerspectiveTransformMatrix(1,0,1));
+
+    for(vtkIdType aCellId = 0; aCellId < aNumCells; aCellId++){
+      vtkCell* aCell = theInput->GetCell(aCellId);
+
+      float aBounds[6];
+      aCell->GetBounds(aBounds);
+
+      float aCenter[3];
+      GetCenter(aBounds,aCenter);
+
+      float aView[4];
+      float aX[4] = {aCenter[0], aCenter[1], aCenter[2], 1.0};
+      aMatrix->MultiplyPoint(aX,aView);
+
+      if(aView[3] == 0.0)
+       continue;
+
+      theRenderer->SetViewPoint(aView[0]/aView[3], 
+                               aView[1]/aView[3],
+                               aView[2]/aView[3]);
+      theRenderer->ViewToDisplay();
+
+      float aDX[3];
+      theRenderer->GetDisplayPoint(aDX);
+      
+      // check whether visible and in selection window 
+      if(aDX[0] >= theSelection[0] && aDX[0] <= theSelection[2] &&
+         aDX[1] >= theSelection[1] && aDX[1] <= theSelection[3])
+      {
+
+       //cout<<"aCellId = "<<aCellId<<": ";
+       vtkIdType aNumPts = aCell->GetNumberOfPoints();
+       bool anIsVisible = true;
+       for(vtkIdType anId = 0; anId < aNumPts; anId++){
+         vtkIdType aPntId = aCell->GetPointId(anId);
+         //cout<<aPntId<<"; ";
+         anIsVisible = aVisibleIds.find(aPntId) != aVisibleIds.end();
+         if(!anIsVisible)
+           break;
+       }
+       //cout<<"\t"<<anIsVisible<<"\n";
+       if(anIsVisible)
+         theVectorIds.push_back(aCellId);
+      }
+    }//for all parts
+  }
+
+  //----------------------------------------------------------------------------
+  void
+  CalculatePickPosition(vtkRenderer *theRenderer,
+                       float theSelectionX, 
+                       float theSelectionY, 
+                       float theSelectionZ,
+                       float thePickPosition[3])
+  {
+    // Convert the selection point into world coordinates.
+    //
+    theRenderer->SetDisplayPoint(theSelectionX, theSelectionY, theSelectionZ);
+    theRenderer->DisplayToWorld();
+    float* aWorldCoords = theRenderer->GetWorldPoint();
+    if ( aWorldCoords[3] != 0.0 ) {
+      for (int i=0; i < 3; i++) {
+       thePickPosition[i] = aWorldCoords[i] / aWorldCoords[3];
+      }
+    }
+  }
+}
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(SVTK_RectPicker);
+
+//----------------------------------------------------------------------------
+SVTK_RectPicker
+::SVTK_RectPicker()
+{
+  this->Tolerance = 0.005;
+  this->PickPoints = 1;
+}
+
+SVTK_RectPicker
+::~SVTK_RectPicker()
+{}
+
+int
+SVTK_RectPicker
+::Pick(float, float, float, vtkRenderer*)
+{
+  return 0;
+}
+
+//----------------------------------------------------------------------------
+int
+SVTK_RectPicker
+::Pick(float theSelection[3], float theSelection2[3], vtkRenderer *theRenderer)
+{
+  return Pick(theSelection[0], theSelection[1], theSelection[2], 
+             theSelection2[0], theSelection2[1], theSelection2[2],
+             theRenderer);
+}
+
+//----------------------------------------------------------------------------
+int 
+SVTK_RectPicker
+::Pick(float theSelectionX, float theSelectionY, float theSelectionZ, 
+       float theSelectionX2, float theSelectionY2, float theSelectionZ2,
+       vtkRenderer *theRenderer)
+{
+  //  Initialize picking process
+  this->Initialize();
+  myCellIdsMap.clear();
+  myPointIdsMap.clear();
+  this->Renderer = theRenderer;
+
+  // Get camera focal point and position. Convert to display (screen) 
+  // coordinates. We need a depth value for z-buffer.
+  //
+  vtkCamera* aCamera = theRenderer->GetActiveCamera();
+
+  float aCameraFP[4];
+  aCamera->GetFocalPoint(aCameraFP); 
+  aCameraFP[3] = 1.0;
+
+  theRenderer->SetWorldPoint(aCameraFP);
+  theRenderer->WorldToDisplay();
+  float* aDisplayCoords = theRenderer->GetDisplayPoint();
+  float aSelectionZ = aDisplayCoords[2];
+
+  this->SelectionPoint[0] = theSelectionX;
+  this->SelectionPoint[1] = theSelectionY;
+  this->SelectionPoint[2] = theSelectionZ;
+
+  // Convert the selection point into world coordinates.
+  //
+  CalculatePickPosition(theRenderer,
+                       theSelectionX,
+                       theSelectionY,
+                       aSelectionZ,
+                       this->PickPosition);
+
+  this->SelectionPoint2[0] = theSelectionX2;
+  this->SelectionPoint2[1] = theSelectionY2;
+  this->SelectionPoint2[2] = theSelectionZ2;
+
+  // Convert the selection point into world coordinates.
+  //
+  CalculatePickPosition(theRenderer,
+                       theSelectionX2,
+                       theSelectionY2,
+                       aSelectionZ,
+                       this->PickPosition2);
+
+  // Invoke start pick method if defined
+  this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
+
+  vtkPropCollection *aProps;
+  if ( this->PickFromList ) 
+    aProps = this->GetPickList();
+  else 
+    aProps = theRenderer->GetProps();
+
+  aProps->InitTraversal();
+  while ( vtkProp* aProp = aProps->GetNextProp() ) {
+    aProp->InitPathTraversal();
+    while ( vtkAssemblyPath* aPath = aProp->GetNextPath() ) {
+      vtkMapper *aMapper = NULL;
+      bool anIsPickable = false;
+      vtkActor* anActor = NULL;
+      vtkProp *aPropCandidate = aPath->GetLastNode()->GetProp();
+      if ( aPropCandidate->GetPickable() && aPropCandidate->GetVisibility() ) {
+        anIsPickable = true;
+       anActor = vtkActor::SafeDownCast(aPropCandidate);
+       if ( anActor ) {
+          aMapper = anActor->GetMapper();
+          if ( anActor->GetProperty()->GetOpacity() <= 0.0 )
+           anIsPickable = false;
+       }
+      }
+      if ( anIsPickable  &&  aMapper && aMapper->GetInput()) {
+       int aSelectionPoint[4] = {int(theSelectionX),
+                                 int(theSelectionY),
+                                 int(theSelectionX2),
+                                 int(theSelectionY2)};
+       if ( this->PickPoints ) {
+         TVectorIds& aVisibleIds = myPointIdsMap[anActor];
+         TVectorIds anInVisibleIds;
+         SelectVisiblePoints(aSelectionPoint,
+                             theRenderer,
+                             aMapper->GetInput(),
+                             aVisibleIds,
+                             anInVisibleIds,
+                             this->Tolerance);
+         if ( aVisibleIds.empty() ) {
+           myPointIdsMap.erase(myPointIdsMap.find(anActor));
+         }
+       } else {
+         TVectorIds& aVectorIds = myCellIdsMap[anActor];
+         SelectVisibleCells(aSelectionPoint,
+                            theRenderer,
+                            aMapper->GetInput(),
+                            aVectorIds,
+                            this->Tolerance);
+         if ( aVectorIds.empty() ) {
+           myCellIdsMap.erase(myCellIdsMap.find(anActor));
+         }
+       }
+      }
+    }
+  }
+
+  // Invoke end pick method if defined
+  this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
+
+  return myPointIdsMap.empty() || myCellIdsMap.empty();
+}
+
+
+//----------------------------------------------------------------------------
+const SVTK_RectPicker::TVectorIdsMap& 
+SVTK_RectPicker
+::GetPointIdsMap() const
+{
+  return myPointIdsMap;
+}
+
+const SVTK_RectPicker::TVectorIdsMap& 
+SVTK_RectPicker
+::GetCellIdsMap() const
+{
+  return myCellIdsMap;
+}
+
diff --git a/src/SVTK/SVTK_RectPicker.h b/src/SVTK/SVTK_RectPicker.h
new file mode 100644 (file)
index 0000000..a9837c2
--- /dev/null
@@ -0,0 +1,112 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SVTK_RectPicker.h
+//  Author : 
+//  Module : SALOME
+
+#ifndef __SVTK_RectPicker_h
+#define __SVTK_RectPicker_h
+
+#include "SVTK.h"
+
+#include <map>
+#include <vector>
+
+#include <vtkAbstractPropPicker.h>
+
+class vtkRenderer;
+
+/*! \class vtkAbstractPropPicker
+ * \brief For more information see <a href="http://www.vtk.org/">VTK documentation
+ */
+/*! \class VTKViewer_RectPicker
+ * \brief Rectangular picker class.
+ */
+class SVTK_EXPORT SVTK_RectPicker : public vtkAbstractPropPicker
+{
+ public:
+  static
+  SVTK_RectPicker *New();
+
+  vtkTypeMacro(SVTK_RectPicker,vtkAbstractPropPicker);
+  
+  /*! 
+    Specify tolerance for performing pick operation. Tolerance is specified
+    as fraction of rendering window size. (Rendering window size is measured
+    across diagonal.)
+  */
+  vtkSetMacro(Tolerance,float);
+  vtkGetMacro(Tolerance,float);
+
+  //! Use these methods to pick points or points and cells
+  vtkSetMacro(PickPoints,int);
+  vtkGetMacro(PickPoints,int);
+  vtkBooleanMacro(PickPoints,int);
+
+  virtual 
+  int
+  Pick(float theSelectionX, float theSelectionY, float theSelectionZ, 
+       float theSelectionX2, float theSelectionY2, float theSelectionZ2,
+       vtkRenderer *theRenderer);  
+
+  int
+  Pick(float theSelection[3], float theSelection2[3], vtkRenderer *theRenderer);
+
+  typedef std::vector<vtkIdType> TVectorIds;
+  typedef std::map<vtkActor*,TVectorIds> TVectorIdsMap;
+
+  const TVectorIdsMap& 
+  GetPointIdsMap() const;
+
+  const TVectorIdsMap& 
+  GetCellIdsMap() const;
+
+ protected:
+  SVTK_RectPicker();
+  ~SVTK_RectPicker();
+
+  //! tolerance for computation (% of window)
+  float Tolerance;
+
+  //! use the following to control picking mode
+  int PickPoints;
+
+  //! second rectangle selection point in window (pixel) coordinates
+  float SelectionPoint2[3]; 
+
+  //! second rectangle selection point in world coordinates
+  float PickPosition2[3]; 
+
+  TVectorIdsMap myPointIdsMap;
+  TVectorIdsMap myCellIdsMap;
+
+ private:
+  virtual 
+  int
+  Pick(float, float, float, vtkRenderer*);
+};
+
+#endif
+
+
diff --git a/src/SVTK/SVTK_RenderWindow.cxx b/src/SVTK/SVTK_RenderWindow.cxx
deleted file mode 100644 (file)
index d24e0a1..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public  
-// 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.salome-platform.org/
-//
-#include "SVTK_RenderWindow.h"
-
-#include <qcolordialog.h>
-#include <qpopupmenu.h>
-
-#include <stdlib.h>
-#include <math.h>
-
-#include <vtkRenderWindowInteractor.h>
-#include <vtkRendererCollection.h>
-#include <vtkCamera.h>
-#ifndef WNT
-#include <vtkXOpenGLRenderWindow.h>
-//#include <GL/gl.h>
-//#include <GL/glu.h>
-//#include <qgl.h>
-#else
-#include <vtkRenderWindow.h>
-#endif
-
-#if QT_VERSION > 300
-#include <qcursor.h>
-#endif
-
-//==========================================================
-SVTK_RenderWindow
-::SVTK_RenderWindow(QWidget* parent, const char* name) :
-  QWidget(parent, name, 
-         Qt::WStyle_NoBorder | Qt::WDestructiveClose | 
-         Qt::WResizeNoErase | Qt::WRepaintNoErase)
-{
-  myRW = vtkRenderWindow::New();
-#ifndef WNT
-  myRW->SetDisplayId((void*)x11Display());
-#endif
-  myRW->SetWindowId((void*)winId());
-  myRW->DoubleBufferOn();
-  setMouseTracking(true);
-}
-
-//==========================================================
-SVTK_RenderWindow
-::~SVTK_RenderWindow() 
-{
-  myRW->Delete();
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::paintEvent(QPaintEvent* theEvent) 
-{
-  myRW->Render();
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::resizeEvent(QResizeEvent* theEvent) 
-{
-  int aWidth = myRW->GetSize()[0], aHeight = myRW->GetSize()[1];
-  if(vtkRenderWindowInteractor* aRWI = myRW->GetInteractor())
-    aRWI->UpdateSize(width(), height());
-  if(aWidth != width() || aHeight != height()){
-    vtkRendererCollection * aRenderers = myRW->GetRenderers();
-    aRenderers->InitTraversal();
-    double aCoeff = 1.0;
-    if(vtkRenderer *aRenderer = aRenderers->GetNextItem()){
-      vtkCamera *aCamera = aRenderer->GetActiveCamera();
-      double aScale = aCamera->GetParallelScale();
-      if((aWidth - width())*(aHeight - height()) > 0)
-        aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight));
-      else
-        aCoeff = double(aWidth)/double(width());
-      aCamera->SetParallelScale(aScale*aCoeff);
-    }
-  }
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::mouseMoveEvent(QMouseEvent* event) 
-{
-  emit MouseMove(event) ;
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::mousePressEvent(QMouseEvent* event) 
-{
-  emit MouseButtonPressed( event );
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::mouseReleaseEvent( QMouseEvent *event )
-{
-  emit MouseButtonReleased( event );
-}
-
-//==========================================================
-void
-SVTK_RenderWindow::mouseDoubleClickEvent( QMouseEvent* event )
-{
-  emit MouseDoubleClicked( event );
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::keyPressEvent (QKeyEvent* event) 
-{
-  emit KeyPressed(event) ;
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::keyReleaseEvent (QKeyEvent * event) 
-{
-  emit KeyReleased(event) ;
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::wheelEvent(QWheelEvent* event)
-{
-  emit WheelMoved(event) ;
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::onChangeBackgroundColor()
-{
-  //float red, green, blue;
-  float backint[3];
-
-  vtkRendererCollection * theRenderers = myRW->GetRenderers();
-  theRenderers->InitTraversal();
-  vtkRenderer * theRenderer = theRenderers->GetNextItem();
-  theRenderer->GetBackground(backint);
-
-  QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );    
-  if ( selColor.isValid() ) {
-    theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. ); 
-  }
-}
-
-//==========================================================
-void
-SVTK_RenderWindow
-::contextMenuEvent ( QContextMenuEvent * e )
-{
-  if ( e->reason() != QContextMenuEvent::Mouse )
-    emit contextMenuRequested( e );
-}
diff --git a/src/SVTK/SVTK_RenderWindow.h b/src/SVTK/SVTK_RenderWindow.h
deleted file mode 100644 (file)
index 35f5b6d..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-//  SALOME VTKViewer : build VTK viewer into Salome desktop
-//
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  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 
-//
-//
-//
-//  File   : VTKViewer_RenderWindow.h
-//  Author : Nicolas REJNERI
-//  Module : SALOME
-//  $Header$
-
-#ifndef SVTK_RenderWindow_h
-#define SVTK_RenderWindow_h
-
-#include <qwidget.h>
-
-#include "SVTK.h"
-
-class vtkRenderWindow;
-
-class SVTK_EXPORT SVTK_RenderWindow : public QWidget
-{
-  Q_OBJECT;
-
-public:
-  SVTK_RenderWindow(QWidget *parent, const char *name);
-  virtual ~SVTK_RenderWindow() ;
-
-  vtkRenderWindow* getRenderWindow() { return myRW; }
-
- protected:
-  virtual void mouseMoveEvent( QMouseEvent* );
-  virtual void mousePressEvent( QMouseEvent* );
-  virtual void mouseReleaseEvent( QMouseEvent* );
-  virtual void mouseDoubleClickEvent( QMouseEvent* );
-  virtual void wheelEvent( QWheelEvent* );
-  virtual void keyPressEvent( QKeyEvent* );
-  virtual void keyReleaseEvent( QKeyEvent* );
-  virtual void paintEvent( QPaintEvent* );
-  virtual void resizeEvent( QResizeEvent* );
-  virtual void onChangeBackgroundColor();
-  virtual void contextMenuEvent( QContextMenuEvent * e );
-
- signals:
-  void MouseMove( QMouseEvent* );
-  void MouseButtonPressed( QMouseEvent* );
-  void MouseButtonReleased( QMouseEvent* );
-  void MouseDoubleClicked( QMouseEvent* );
-  void WheelMoved( QWheelEvent* );
-  void LeftButtonPressed(const QMouseEvent *event) ;
-  void LeftButtonReleased(const QMouseEvent *event) ;
-  void MiddleButtonPressed(const QMouseEvent *event) ;
-  void MiddleButtonReleased(const QMouseEvent *event) ;
-  void RightButtonPressed(const QMouseEvent *event) ;
-  void RightButtonReleased(const QMouseEvent *event) ;
-  void ButtonPressed(const QMouseEvent *event);
-  void ButtonReleased(const QMouseEvent *event);
-  void KeyPressed( QKeyEvent* );
-  void KeyReleased( QKeyEvent* );
-  void contextMenuRequested( QContextMenuEvent *e );
-
- protected:
-  vtkRenderWindow* myRW;
-};
-
-#endif
index 55dd794e7f4c20a6a7fa06daf95f9df5cf4af139..a2b8aa176ab3623824c19fa99080b5a5900bebba 100644 (file)
 //
 //
 //
-//  File   : VTKViewer_RenderWindowInteractor.cxx
-//  Author : Nicolas REJNERI
+//  File   : 
+//  Author : 
 //  Module : SALOME
 //  $Header$
 
 #include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_GenericRenderWindowInteractor.h"
 
 #include "SVTK_InteractorStyle.h"
-#include "SVTK_RenderWindow.h"
-#include "SVTK_ViewWindow.h"
-
-#include "VTKViewer_Algorithm.h"
+#include "SVTK_Renderer.h"
 #include "SVTK_Functor.h"
-#include "SVTK_Actor.h"
+#include "SALOME_Actor.h"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
+#include "SVTK_SpaceMouse.h" 
+#include "SVTK_Event.h" 
+
+#include "VTKViewer_Algorithm.h"
 
 // VTK Includes
 #include <vtkObjectFactory.h>
-#include <vtkPicker.h>
-#include <vtkCellPicker.h>
-#include <vtkPointPicker.h>
 #include <vtkRendererCollection.h>
 #include <vtkRenderWindow.h>
+#include <vtkGenericRenderWindowInteractor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkCommand.h>
+#include <vtkPicker.h>
+#include <vtkCamera.h>
 
 // QT Includes
-#include <qkeycode.h>
-
-#include <TColStd_IndexedMapOfInteger.hxx>
+#include <qtimer.h>
+#include <qapplication.h>
+#include <qcolordialog.h>
+#include <qpaintdevice.h>
 
 using namespace std;
 
-SVTK_RenderWindowInteractor* 
-SVTK_RenderWindowInteractor
-::New() 
-{
-  vtkObject *ret = vtkObjectFactory::CreateInstance("SVTK_RenderWindowInteractor") ;
-  if( ret ) {
-    return dynamic_cast<SVTK_RenderWindowInteractor *>(ret) ;
-  }
-  return new SVTK_RenderWindowInteractor;
-}
-
-SVTK_RenderWindowInteractor
-::SVTK_RenderWindowInteractor() 
-{
-  this->Enabled = 0 ;
-  this->mTimer = new QTimer( this ) ;
-  myDisplayMode = 0;
-  myGUIWindow = 0;
-
-  myBasicPicker = vtkPicker::New();
-  myCellPicker = vtkCellPicker::New();
-  myPointPicker = vtkPointPicker::New();
+static bool GENERATE_SUIT_EVENTS = false;
+static bool FOCUS_UNDER_MOUSE = false;
 
-  myCellActor = SVTK_Actor::New(); 
-  myCellActor->PickableOff();
-  myCellActor->GetProperty()->SetColor(1,1,0);
-  myCellActor->GetProperty()->SetLineWidth(5);
-  myCellActor->GetProperty()->SetRepresentationToSurface();
 
-  myEdgeActor = SVTK_Actor::New(); 
-  myEdgeActor->PickableOff();
-  myEdgeActor->GetProperty()->SetColor(1,0,0);
-  myEdgeActor->GetProperty()->SetLineWidth(5);
-  myEdgeActor->GetProperty()->SetRepresentationToWireframe();
+//----------------------------------------------------------------------------
+QVTK_RenderWindowInteractor
+::QVTK_RenderWindowInteractor(QWidget* theParent, 
+                             const char* theName):
+  QWidget(theParent,theName,Qt::WNoAutoErase),
+  myRenderWindow(vtkRenderWindow::New())
+{
+  setMouseTracking(true);
 
-  myPointActor = SVTK_Actor::New(); 
-  myPointActor->PickableOff();
-  myPointActor->GetProperty()->SetColor(1,1,0);
-  myPointActor->GetProperty()->SetPointSize(5);
-  myPointActor->GetProperty()->SetRepresentationToPoints();
+  myRenderWindow->Delete();
+  myRenderWindow->DoubleBufferOn();
 
-  connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
+#ifndef WNT
+  myRenderWindow->SetDisplayId((void*)x11Display());
+#endif
+  myRenderWindow->SetWindowId((void*)winId());
 }
 
 
-SVTK_RenderWindowInteractor
-::~SVTK_RenderWindowInteractor() 
+void 
+QVTK_RenderWindowInteractor
+::Initialize(vtkGenericRenderWindowInteractor* theDevice)
 {
-  delete mTimer ;
+  if(GetDevice())
+    myDevice->SetRenderWindow(NULL);
 
-  myViewWindow->RemoveActor(myCellActor);
-  myViewWindow->RemoveActor(myEdgeActor);
-  myViewWindow->RemoveActor(myPointActor);
+  myDevice = theDevice;
 
-  myCellActor->Delete();
-  myEdgeActor->Delete();
-  myPointActor->Delete();
-
-  myBasicPicker->Delete();
-  myCellPicker->Delete();
-  myPointPicker->Delete();
+  if(theDevice)
+    theDevice->SetRenderWindow(getRenderWindow());
 }
 
-//
-// We never allow the SVTK_RenderWindowInteractor to control 
-// the event loop. The application always has the control. 
-//
-void
-SVTK_RenderWindowInteractor
-::Initialize() 
-{
-  //
-  // We cannot do much unless there is a render window 
-  // associated with this interactor. 
-  //
-  if( ! RenderWindow ) {
-    vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize(): No render window attached!") ;
-    return ;
-  }
-
-  //
-  // We cannot hand a render window which is not a VTKViewer_RenderWindow. 
-  // One way to force this is to use dynamic_cast and hope that 
-  // it works. If the dynamic_cast does not work, we flag an error
-  // and get the hell out.
-  //
-  vtkRenderWindow *aRenderWindow = dynamic_cast<vtkRenderWindow *>(RenderWindow) ;
-  if( !aRenderWindow ) {
-    vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
-    return ;
-  }
-
-  //
-  // If the render window has zero size, then set it to a default 
-  // value of 300x300.
-  // 
-  int* aSize = aRenderWindow->GetSize();
-  this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300);
-  this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300);
-
-  this->SetPicker(myBasicPicker);
-
-  SetSelectionTolerance();
-
-  //
-  // Enable the interactor. 
-  //
-  this->Enable() ;
-
-  //
-  // Start the rendering of the window. 
-  //
-  aRenderWindow->Start() ;
-
-  //
-  // The interactor has been initialized.
-  //
-  this->Initialized = 1 ;
-
-  return ;
+//----------------------------------------------------------------------------
+QVTK_RenderWindowInteractor
+::~QVTK_RenderWindowInteractor() 
+{
+  if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance())
+    if(aSpaceMouse->isSpaceMouseOn())
+      aSpaceMouse->close(x11Display());
 }
 
 
 //----------------------------------------------------------------------------
-void
-SVTK_RenderWindowInteractor
-::setGUIWindow(QWidget* theWindow)
+vtkGenericRenderWindowInteractor* 
+QVTK_RenderWindowInteractor
+::GetDevice()
 {
-  myGUIWindow = theWindow;
+  return myDevice.GetPointer();
 }
 
 //----------------------------------------------------------------------------
-void
-SVTK_RenderWindowInteractor
-::setViewWindow(SVTK_ViewWindow* theViewWindow)
+vtkRenderWindow*
+QVTK_RenderWindowInteractor
+::getRenderWindow()
 {
-  myViewWindow = theViewWindow;
-
-  myViewWindow->InsertActor(myCellActor);
-  myViewWindow->InsertActor(myEdgeActor);
-  myViewWindow->InsertActor(myPointActor);
+  return myRenderWindow.GetPointer();
 }
 
 //----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::MoveInternalActors()
+QVTK_RenderWindowInteractor
+::InvokeEvent(unsigned long theEvent, void* theCallData)
 {
-  myViewWindow->MoveActor(myCellActor);
-  myViewWindow->MoveActor(myEdgeActor);
-  myViewWindow->MoveActor(myPointActor);
+  GetDevice()->InvokeEvent(theEvent,theCallData);
 }
 
 //----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::SetInteractorStyle(vtkInteractorObserver *theInteractor)
+QVTK_RenderWindowInteractor
+::show()
 {
-  myInteractorStyle = dynamic_cast<SVTK_InteractorStyle*>(theInteractor);
-  vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
+  QWidget::show();
+  update(); // needed for initial contents display on Win32
 }
 
-
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::SetSelectionMode(Selection_Mode theMode)
+QVTK_RenderWindowInteractor
+::polish()
 {
-  myCellActor->SetVisibility(false);
-  myEdgeActor->SetVisibility(false);
-  myPointActor->SetVisibility(false);
-
-  switch(theMode){
-  case ActorSelection:
-    this->SetPicker(myBasicPicker);
-    break;
-  case NodeSelection:
-    this->SetPicker(myPointPicker);
-    break;
-  case CellSelection:
-  case EdgeSelection:
-  case FaceSelection:
-  case VolumeSelection:
-  case EdgeOfCellSelection:
-    this->SetPicker(myCellPicker);
-    break;
+  // Final initialization just before the widget is displayed
+  GetDevice()->SetSize(width(),height());
+  if(!GetDevice()->GetInitialized()){
+    GetDevice()->Initialize();
+    GetDevice()->ConfigureEvent();
   }
-
-  myInteractorStyle->OnSelectionModeChanged();
 }
 
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::SetSelectionProp(const double& theRed, 
-                  const double& theGreen, 
-                  const double& theBlue, 
-                  const int& theWidth) 
+QVTK_RenderWindowInteractor
+::resize(int w, int h) 
 {
-  myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
-  myCellActor->GetProperty()->SetLineWidth(theWidth);
-
-  myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
-  myPointActor->GetProperty()->SetPointSize(theWidth);
+  GetDevice()->UpdateSize(w,h);
 }
 
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::SetSelectionTolerance(const double& theTolNodes, 
-                       const double& theTolItems)
+QVTK_RenderWindowInteractor
+::paintEvent( QPaintEvent* theEvent ) 
 {
-  myTolNodes = theTolNodes;
-  myTolItems = theTolItems;
-
-  myBasicPicker->SetTolerance(myTolItems);
-  myCellPicker->SetTolerance(myTolItems);
-  myPointPicker->SetTolerance(myTolNodes);
-
+  GetDevice()->Render();
 }
 
-// ================================== 
-void
-SVTK_RenderWindowInteractor
-::Start() 
-{
-  //
-  // We do not allow this interactor to control the 
-  // event loop. Only the QtApplication objects are
-  // allowed to do that. 
-  //
-  vtkErrorMacro(<<"SVTK_RenderWindowInteractor::Start() not allowed to start event loop.") ;
-  return ;
-}
 
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::UpdateSize(int w, int h) 
-{
-  // if the size changed send this on to the RenderWindow
-  if ((w != this->Size[0])||(h != this->Size[1])) {
-    this->Size[0] = w;
-    this->Size[1] = h;
-    this->RenderWindow->SetSize(w,h);
+QVTK_RenderWindowInteractor
+::resizeEvent( QResizeEvent* theEvent )
+{
+  int* aSize = getRenderWindow()->GetSize();
+  int aWidth = aSize[0];
+  int aHeight = aSize[1];
+
+  GetDevice()->UpdateSize(width(),height());
+
+  if(isVisible() && aWidth && aHeight){
+    if( aWidth != width() || aHeight != height() ) {
+      vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers();
+      aRenderers->InitTraversal();
+      double aCoeff = 1.0;
+      if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) {
+       vtkCamera *aCamera = aRenderer->GetActiveCamera();
+       double aScale = aCamera->GetParallelScale();
+       if((aWidth - width())*(aHeight - height()) > 0)
+         aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight));
+       else
+         aCoeff = double(aWidth)/double(width());
+       aCamera->SetParallelScale(aScale*aCoeff);
+      }
+    }
   }
-}
 
-int
-SVTK_RenderWindowInteractor
-::CreateTimer(int vtkNotUsed(timertype)) 
-{
-  //
-  // Start a one-shot timer for 10ms. 
-  //
-  mTimer->start(10, TRUE) ;
-  return 1 ;
+  update(); 
 }
 
-int
-SVTK_RenderWindowInteractor
-::DestroyTimer(void) 
-{
-  //
-  // :TRICKY: Tue May  2 00:17:32 2000 Pagey
-  //
-  // QTimer will automatically expire after 10ms. So 
-  // we do not need to do anything here. In fact, we 
-  // should not even Stop() the QTimer here because doing 
-  // this will skip some of the processing that the TimerFunc()
-  // does and will result in undesirable effects. For 
-  // example, this will result in vtkLODActor to leave
-  // the models in low-res mode after the mouse stops
-  // moving. 
-  //
-  return 1 ;
-}
 
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::TimerFunc() 
-{
-  if( ! this->Enabled ) {
-    return ;
-  }
+QVTK_RenderWindowInteractor
+::contextMenuEvent( QContextMenuEvent* event )
+{}
 
-  myInteractorStyle->OnTimer();
 
-  emit RenderWindowModified();
+//----------------------------------------------------------------------------
+void
+QVTK_RenderWindowInteractor
+::mouseMoveEvent( QMouseEvent* event ) 
+{
+  GetDevice()->SetEventInformationFlipY(event->x(), 
+                                       event->y(),
+                                       event->state() & ControlButton,
+                                       event->state() & ShiftButton);
+  GetDevice()->MouseMoveEvent();
 }
 
+
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::MouseMove(const QMouseEvent *event
+QVTK_RenderWindowInteractor
+::mousePressEvent( QMouseEvent* event 
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ;
-  if (myInteractorStyle->needsRedrawing() )
-    emit RenderWindowModified() ; 
+  GetDevice()->SetEventInformationFlipY(event->x(), 
+                                       event->y(),
+                                       event->state() & ControlButton,
+                                       event->state() & ShiftButton);
+  if( event->button() & LeftButton )
+    GetDevice()->LeftButtonPressEvent();
+  else if( event->button() & MidButton )
+    GetDevice()->MiddleButtonPressEvent();
+  else if( event->button() & RightButton )
+    GetDevice()->RightButtonPressEvent();
 }
 
+
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::LeftButtonPressed(const QMouseEvent *event) 
+QVTK_RenderWindowInteractor
+::mouseReleaseEvent( QMouseEvent *event )
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), 
-                                     (event->state() & ShiftButton), 
-                                     event->x(), event->y());
+  GetDevice()->SetEventInformationFlipY(event->x(), 
+                                       event->y(),
+                                       event->state() & ControlButton,
+                                       event->state() & ShiftButton);
+
+  if( event->button() & LeftButton )
+    GetDevice()->LeftButtonReleaseEvent();
+  else if( event->button() & MidButton )
+    GetDevice()->MiddleButtonReleaseEvent();
+  else if( event->button() & RightButton )
+    GetDevice()->RightButtonReleaseEvent();
 }
 
+
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::LeftButtonReleased(const QMouseEvent *event) {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), 
-                                    (event->state() & ShiftButton), 
-                                    event->x(), event->y() ) ;
-}
+QVTK_RenderWindowInteractor
+::mouseDoubleClickEvent( QMouseEvent* event )
+{}
 
-void 
-SVTK_RenderWindowInteractor
-::MiddleButtonPressed(const QMouseEvent *event) 
-{
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), 
-                                       (event->state() & ShiftButton), 
-                                       event->x(), event->y() ) ;
-}
 
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::MiddleButtonReleased(const QMouseEvent *event) 
+QVTK_RenderWindowInteractor
+::wheelEvent( QWheelEvent* event )
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), 
-                                      (event->state() & ShiftButton), 
-                                      event->x(), event->y() ) ;
+  setActiveWindow();
+  setFocus();
 }
 
+
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::RightButtonPressed(const QMouseEvent *event
+QVTK_RenderWindowInteractor
+::keyPressEvent( QKeyEvent* event 
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), 
-                                       (event->state() & ShiftButton), 
-                                       event->x(), event->y() ) ;
+  GetDevice()->SetKeyEventInformation(event->state() & ControlButton,
+                                     event->state() & ShiftButton,
+                                     event->key());
+  GetDevice()->KeyPressEvent();
+  GetDevice()->CharEvent();
 }
 
+//----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::RightButtonReleased(const QMouseEvent *event
+QVTK_RenderWindowInteractor
+::keyReleaseEvent( QKeyEvent * event 
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton), 
-                                     (event->state() & ShiftButton), 
-                                     event->x(), event->y() ) ;
-
-  if(myInteractorStyle->GetState() == VTK_INTERACTOR_STYLE_CAMERA_NONE && !( event->state() & KeyButtonMask )){
-    QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
-                              event->pos(), event->globalPos(),
-                              event->state() );
-    emit contextMenuRequested( &aEvent );
-  }
+  GetDevice()->SetKeyEventInformation(event->state() & ControlButton,
+                                     event->state() & ShiftButton,
+                                     event->key());
+  GetDevice()->KeyReleaseEvent();
 }
 
-void
-SVTK_RenderWindowInteractor
-::ButtonPressed(const QMouseEvent *event) 
+
+//----------------------------------------------------------------------------
+void  
+QVTK_RenderWindowInteractor
+::enterEvent( QEvent* event )
 {
-  return ;
+  if(FOCUS_UNDER_MOUSE){
+    setActiveWindow();
+    setFocus();
+  }
+  GetDevice()->EnterEvent();
 }
 
-void
-SVTK_RenderWindowInteractor
-::ButtonReleased(const QMouseEvent *event) 
+//----------------------------------------------------------------------------
+void  
+QVTK_RenderWindowInteractor
+::leaveEvent( QEvent * )
 {
-  return ;
+  GetDevice()->LeaveEvent();
 }
 
 
-int
-SVTK_RenderWindowInteractor
-::GetDisplayMode() 
-{
-  return myDisplayMode;
+//----------------------------------------------------------------------------
+void  
+QVTK_RenderWindowInteractor
+::focusInEvent( QFocusEvent* event )
+{
+  QWidget::focusInEvent( event );
+
+  // register set space mouse events receiver
+  if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){
+    if(!aSpaceMouse->isSpaceMouseOn()) {// initialize 3D space mouse driver 
+      aSpaceMouse->initialize(x11Display(),winId());
+    }else{
+      aSpaceMouse->setWindow(x11Display(),winId());
+    }
+  }
 }
 
-void
-SVTK_RenderWindowInteractor
-::SetDisplayMode(int theMode)
+//----------------------------------------------------------------------------
+void  
+QVTK_RenderWindowInteractor
+::focusOutEvent ( QFocusEvent* event )
 {
-  if(theMode == 0) 
-    ChangeRepresentationToWireframe();
-  else 
-    ChangeRepresentationToSurface();
-  myDisplayMode = theMode;
+  QWidget::focusOutEvent( event );
+
+  // unregister set space mouse events receiver
+  if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){
+    if(aSpaceMouse->isSpaceMouseOn())
+      aSpaceMouse->setWindow(x11Display(),0);
+  }
 }
 
 
-void
-SVTK_RenderWindowInteractor
-::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, 
-                int theMode)
-{
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,int>
-                         (&SALOME_Actor::setDisplayMode,theMode));
+//----------------------------------------------------------------------------
+bool 
+QVTK_RenderWindowInteractor
+::x11Event( XEvent *xEvent )
+{
+  // handle 3d space mouse events
+  if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){
+    if(aSpaceMouse->isSpaceMouseOn() && xEvent->type == ClientMessage){
+      SVTK_SpaceMouse::MoveEvent anEvent;
+      int type = aSpaceMouse->translateEvent( x11Display(), xEvent, &anEvent, 1.0, 1.0 );
+      switch( type ){
+      case SVTK_SpaceMouse::SpaceMouseMove : 
+       GetDevice()->InvokeEvent(SVTK::SpaceMouseMoveEvent, anEvent.data );
+       break;
+      case SVTK_SpaceMouse::SpaceButtonPress :
+       GetDevice()->InvokeEvent( SVTK::SpaceMouseButtonEvent, &anEvent.button );
+       break;
+      case SVTK_SpaceMouse::SpaceButtonRelease :
+       break;
+      }
+      return true; // stop handling the event
+    }
+  }
+
+  return QWidget::x11Event( xEvent );
 }
 
 
-void
+//----------------------------------------------------------------------------
 SVTK_RenderWindowInteractor
-::ChangeRepresentationToWireframe()
+::SVTK_RenderWindowInteractor(QWidget* theParent, 
+                              const char* theName):
+  QVTK_RenderWindowInteractor(theParent,theName),
+  myEventCallbackCommand(vtkCallbackCommand::New())
 {
-  ChangeRepresentationToWireframe(GetRenderer()->GetActors());
+  myEventCallbackCommand->Delete();
+
+  myEventCallbackCommand->SetClientData(this); 
+  myPriority = 0.0;
+
+  myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents);
 }
 
 void
 SVTK_RenderWindowInteractor
-::ChangeRepresentationToSurface()
+::Initialize(vtkGenericRenderWindowInteractor* theDevice,
+            SVTK_Renderer* theRenderer,
+            SVTK_Selector* theSelector)
 {
-  ChangeRepresentationToSurface(GetRenderer()->GetActors());
+  QVTK_RenderWindowInteractor::Initialize(theDevice);
+  SetRenderer(theRenderer);
+  SetSelector(theSelector);
 }
 
-
-void
+//----------------------------------------------------------------------------
 SVTK_RenderWindowInteractor
-::ChangeRepresentationToWireframe(vtkActorCollection* theCollection)
+::~SVTK_RenderWindowInteractor() 
 {
-  using namespace VTK;
-  ForEach<SALOME_Actor>(theCollection,
-                       TSetFunction<SALOME_Actor,int>
-                       (&SALOME_Actor::setDisplayMode,0));
-  emit RenderWindowModified();
+  // Sequence of the destruction call are fixed and should be changed.
+  // vtkRenderWindow instance should be destroyed after all vtkRenderer's
+  GetDevice()->SetInteractorStyle(NULL); 
+  while(!myInteractorStyles.empty()){
+    const PInteractorStyle& aStyle = myInteractorStyles.top();
+    aStyle->SetInteractor(NULL);
+    myInteractorStyles.pop();
+  }
+
+  SetRenderer(NULL);
+
+  GetDevice()->SetRenderWindow(NULL);
 }
 
-void
+//----------------------------------------------------------------------------
+SVTK_Renderer* 
 SVTK_RenderWindowInteractor
-::ChangeRepresentationToSurface(vtkActorCollection* theCollection)
+::GetRenderer()
 {
-  using namespace VTK;
-  ForEach<SALOME_Actor>(theCollection,
-                       TSetFunction<SALOME_Actor,int>
-                       (&SALOME_Actor::setDisplayMode,1));
-  emit RenderWindowModified();
+  return myRenderer.GetPointer();
 }
 
-
 vtkRenderer* 
 SVTK_RenderWindowInteractor
-::GetRenderer()
+::getRenderer()
 {
-  vtkRendererCollection * theRenderers =  this->RenderWindow->GetRenderers();
-  theRenderers->InitTraversal();
-  return theRenderers->GetNextItem();
+  return GetRenderer()->GetDevice();
 }
 
-
-struct TErase{
-  VTK::TSetFunction<vtkActor,int> mySetFunction;
-  TErase():
-    mySetFunction(&vtkActor::SetVisibility,false)
-  {}
-  void operator()(SALOME_Actor* theActor){
-    theActor->SetVisibility(false);
-    // Erase dependent actors
-    vtkActorCollection* aCollection = vtkActorCollection::New(); 
-    theActor->GetChildActors(aCollection);
-    VTK::ForEach<vtkActor>(aCollection,mySetFunction);
-    aCollection->Delete();
-  }
-};
-
 void
 SVTK_RenderWindowInteractor
-::EraseAll()
-{   
-  using namespace VTK;
-  ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
-                       TErase());
+::SetRenderer(SVTK_Renderer* theRenderer)
+{
+  if(theRenderer == myRenderer.GetPointer())
+    return;
 
-  emit RenderWindowModified() ;
-}
+  if(GetRenderer())
+    myRenderWindow->RemoveRenderer(getRenderer());
 
-void
-SVTK_RenderWindowInteractor
-::DisplayAll()
-{ 
-  vtkActorCollection* aCollection = GetRenderer()->GetActors();
-  using namespace VTK;
-  ForEach<SALOME_Actor>(aCollection,TSetVisibility<SALOME_Actor>(true));
+  myRenderer = theRenderer;
 
-  emit RenderWindowModified() ;
+  if(GetRenderer())
+    myRenderWindow->AddRenderer(getRenderer());
 }
 
 
+//----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::Erase(SALOME_Actor* theActor, bool update)
+::InitInteractorStyle(vtkInteractorStyle* theStyle)
 {
-  TErase()(theActor);
-
-  if(update)
-    emit RenderWindowModified();
+  GetDevice()->SetInteractorStyle(theStyle); 
 }
 
 
+//----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::Erase(const Handle(SALOME_InteractiveObject)& theIObject, 
-       bool update)
+::PushInteractorStyle(vtkInteractorStyle* theStyle)
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TErase());
-
-  if(update)
-    emit RenderWindowModified();
+  myInteractorStyles.push(PInteractorStyle(theStyle));
+  InitInteractorStyle(theStyle);
 }
 
 
-struct TRemoveAction{
-  vtkRenderer* myRen;
-  TRemoveAction(vtkRenderer* theRen): myRen(theRen){}
-  void operator()(SALOME_Actor* theActor){
-    myRen->RemoveActor(theActor);
-  }
-};
-
-void
-SVTK_RenderWindowInteractor
-::Remove(const Handle(SALOME_InteractiveObject)& theIObject, 
-        bool update)
-{
-  vtkRenderer* aRen = GetRenderer();
-
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(aRen->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TRemoveAction(aRen));
-}
-
+//----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::Remove( SALOME_Actor* SActor, bool updateViewer )
+::PopInteractorStyle()
 {
-  if ( SActor != 0 )
-  {
-    GetRenderer()->RemoveProp( SActor );
-    if ( updateViewer )
-      emit RenderWindowModified();
-  }
-}
-
-void
-SVTK_RenderWindowInteractor
-::RemoveAll( const bool updateViewer )
-{
-  vtkRenderer* aRenderer = GetRenderer();
-  vtkActorCollection* anActors = aRenderer->GetActors();
-  if ( anActors )
-  {
-    anActors->InitTraversal();
-    while ( vtkActor *anAct = anActors->GetNextActor() )
-    {
-      if ( anAct->IsA( "SALOME_Actor" ) )
-      {
-        SALOME_Actor* aSAct = (SALOME_Actor*)anAct;
-        if ( aSAct->hasIO() && aSAct->getIO()->hasEntry() )
-          aRenderer->RemoveActor( anAct );
-      }
-    }
-
-    if ( updateViewer )
-      emit RenderWindowModified();
-  }
+  if(GetInteractorStyle())
+    myInteractorStyles.pop();
+  
+  if(GetInteractorStyle()) 
+    InitInteractorStyle(GetInteractorStyle());
 }
 
 
-float
+//----------------------------------------------------------------------------
+vtkInteractorStyle* 
 SVTK_RenderWindowInteractor
-::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) 
+::GetInteractorStyle()
 {
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  if(anActor)
-    return 1.0 - anActor->GetOpacity();
-  return -1.0;
+  return myInteractorStyles.empty() ? 0 : myInteractorStyles.top().GetPointer();
 }
 
 
-void
+//----------------------------------------------------------------------------
+SVTK_Selector* 
 SVTK_RenderWindowInteractor
-::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, 
-                 float theTrans)
-{
-  float anOpacity = 1.0 - theTrans;
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,float>
-                         (&SALOME_Actor::SetOpacity,anOpacity));
+::GetSelector() 
+{ 
+  return mySelector.GetPointer(); 
 }
 
 
 void
 SVTK_RenderWindowInteractor
-::Display(SALOME_Actor* theActor, bool update)
-{
-  GetRenderer()->AddActor(theActor);
-  theActor->SetVisibility(true);
+::SetSelector(SVTK_Selector* theSelector)
+{ 
+  if(mySelector.GetPointer())
+    mySelector->RemoveObserver(myEventCallbackCommand.GetPointer());
+
+  mySelector = theSelector; 
 
-  if(update)
-    emit RenderWindowModified();
+  if(mySelector.GetPointer())
+    mySelector->AddObserver(vtkCommand::EndPickEvent, 
+                           myEventCallbackCommand.GetPointer(), 
+                           myPriority);
 }
 
 
-void
+//----------------------------------------------------------------------------
+void 
 SVTK_RenderWindowInteractor
-::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
+::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
+               unsigned long theEvent,
+               void* theClientData, 
+               void* vtkNotUsed(theCallData))
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetVisibility<SALOME_Actor>(true));
+  SVTK_RenderWindowInteractor* self = reinterpret_cast<SVTK_RenderWindowInteractor*>(theClientData);
 
-  if(update)
-    emit RenderWindowModified() ;
+  switch(theEvent){
+  case vtkCommand::EndPickEvent:
+    self->onEmitSelectionChanged();
+    break;
+  }
 }
 
 
+//----------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::KeyPressed(QKeyEvent *event)
-{}
-
-
-struct THighlightAction{
-  bool myIsHighlight;
-  SVTK_InteractorStyle* myInteractorStyle;
-  THighlightAction(SVTK_InteractorStyle* theInteractorStyle,
-                  bool theIsHighlight): 
-    myInteractorStyle(theInteractorStyle),
-    myIsHighlight(theIsHighlight)
-  {}
-  void operator()(SALOME_Actor* theActor){
-    if(theActor->GetMapper()){
-      if(theActor->hasHighlight())
-       theActor->highlight(myIsHighlight);
-      else{
-       if(theActor->GetVisibility() && myIsHighlight)
-         myInteractorStyle->HighlightProp(theActor);
-       else if(!myIsHighlight)
-         myInteractorStyle->HighlightProp(NULL);
-      }
-    }
-  }
-};
-
-bool
-SVTK_RenderWindowInteractor
-::highlight( const Handle(SALOME_InteractiveObject)& theIObject, 
-            bool hilight, 
-            bool update)
+::SetSelectionMode(Selection_Mode theMode)
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         THighlightAction(myInteractorStyle,hilight));
-
-  if(update)
-    emit RenderWindowModified();
-
-  return false;
+  mySelector->SetSelectionMode(theMode);
 }
 
 
-struct TUpdateAction{
-  void operator()(vtkActor* theActor){
-    theActor->ApplyProperties();
-  }
-};
-
-void
+//----------------------------------------------------------------
+Selection_Mode
 SVTK_RenderWindowInteractor
-::Update() 
+::SelectionMode() const
 {
-  vtkRenderer* aRen = GetRenderer();
-
-  using namespace VTK;
-  ForEach<vtkActor>(aRen->GetActors(),TUpdateAction());
-
-  aRen->ResetCamera();
-
-  emit RenderWindowModified();  
+  return mySelector->SelectionMode();
 }
 
 
+//----------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::unHighlightSubSelection()
+::onEmitSelectionChanged()
 {
-  myPointActor->SetVisibility(false);
-  myEdgeActor->SetVisibility(false);
-  myCellActor->SetVisibility(false);
+  return emit selectionChanged();
 }
 
 
-bool
+//----------------------------------------------------------------------------
+void
 SVTK_RenderWindowInteractor
-::unHighlightAll()
+::mouseMoveEvent( QMouseEvent* event ) 
 {
-  unHighlightSubSelection();
-
-  using namespace VTK;
-  ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
-                       THighlightAction(myInteractorStyle,false));
+  QVTK_RenderWindowInteractor::mouseMoveEvent(event);
 
-  emit RenderWindowModified() ;
-
-  return false;
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseMove( event );
 }
 
-//-----------------
-// Color methods
-//-----------------
 
+//----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor
+::mousePressEvent( QMouseEvent* event 
 {
-  float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.};
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,const float*>
-                         (&SALOME_Actor::SetColor,aColor));
-}
-
+  QVTK_RenderWindowInteractor::mousePressEvent(event);
 
-QColor
-SVTK_RenderWindowInteractor
-::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) 
-{
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  if(anActor){
-    float r,g,b;
-    anActor->GetColor(r,g,b);
-    return QColor(int(r*255),int(g*255),int(b*255));
-  }
-  return QColor(0,0,0);
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseButtonPressed( event );
 }
 
 
-bool
+//----------------------------------------------------------------------------
+void
 SVTK_RenderWindowInteractor
-::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
+::mouseReleaseEvent( QMouseEvent *event )
 {
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  return anActor != NULL;
-}
+  QVTK_RenderWindowInteractor::mouseReleaseEvent(event);
 
-
-bool
-SVTK_RenderWindowInteractor
-::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
-{
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  return anActor != NULL && anActor->GetVisibility();
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseButtonReleased( event );
 }
 
 
+//----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName)
+::mouseDoubleClickEvent( QMouseEvent* event )
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,const char*,QString>
-                         (&SALOME_Actor::setName,theName.latin1()));
+  QVTK_RenderWindowInteractor::mouseDoubleClickEvent(event);
+
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseDoubleClicked( event );
 }
 
 
 //----------------------------------------------------------------------------
-bool
-SVTK_RenderWindowInteractor
-::highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
-           SALOME_Actor* theMapActor, 
-           SVTK_Actor* theActor,
-           TUpdateActor theFun, 
-           bool hilight, 
-           bool update)
-{
-  if(theMapIndex.Extent() == 0) return false;
-  
-  if (hilight) {
-    setActorData(theMapIndex,theMapActor,theActor,theFun);
-    theActor->SetVisibility(true);
-  }
-  else {
-    theActor->SetVisibility(false);
-  }
-
-  if(update){
-    this->RenderWindow->Render();  
-    emit RenderWindowModified() ;
-  }
-
-  return false;
-}
-  
 void
 SVTK_RenderWindowInteractor
-::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
-              SALOME_Actor* theMapActor,
-              SVTK_Actor *theActor,
-              TUpdateActor theFun)
+::wheelEvent( QWheelEvent* event )
 {
-  (*theFun)(theMapIndex,theMapActor,theActor);
-  float aPos[3];
-  theMapActor->GetPosition(aPos);
-  theActor->SetPosition(aPos);
-}
+  QVTK_RenderWindowInteractor::wheelEvent(event);
 
+  if(event->delta() > 0)
+    GetDevice()->InvokeEvent(SVTK::ZoomInEvent,NULL);
+  else
+    GetDevice()->InvokeEvent(SVTK::ZoomOutEvent,NULL);
 
-//----------------------------------------------------------------------------
-static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
-                            SALOME_Actor* theMapActor, 
-                            SVTK_Actor* theActor)
-{
-  theActor->MapCells(theMapActor,theMapIndex);
-}
-  
-bool
-SVTK_RenderWindowInteractor
-::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex,
-               SALOME_Actor* theMapActor, 
-               bool hilight, 
-               bool update)
-{
-  return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update);
-}
-  
-void 
-SVTK_RenderWindowInteractor
-::setCellData(const int& theIndex, 
-             SALOME_Actor* theMapActor,
-             SVTK_Actor* theActor)
-{
-  TColStd_IndexedMapOfInteger MapIndex; 
-  MapIndex.Add(theIndex);
-  theActor->MapCells(theMapActor,MapIndex);
+  if(GENERATE_SUIT_EVENTS)
+    emit WheelMoved( event );
 }
 
 
 //----------------------------------------------------------------------------
-static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
-                             SALOME_Actor* theMapActor, 
-                             SVTK_Actor* theActor)
-{
-  theActor->MapPoints(theMapActor,theMapIndex);
-}
-  
-bool
+void
 SVTK_RenderWindowInteractor
-::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex,
-                SALOME_Actor* theMapActor, 
-                bool hilight, 
-                bool update)
+::keyPressEvent( QKeyEvent* event ) 
 {
-  return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update);
+  QVTK_RenderWindowInteractor::keyPressEvent(event);
+
+  if(GENERATE_SUIT_EVENTS)
+    emit KeyPressed( event );
 }
-  
+
+//----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::setPointData(const int& theIndex, 
-              SALOME_Actor* theMapActor,
-              SVTK_Actor* theActor)
+::keyReleaseEvent( QKeyEvent * event ) 
 {
-  TColStd_IndexedMapOfInteger MapIndex; 
-  MapIndex.Add(theIndex);
-  theActor->MapPoints(theMapActor,MapIndex);
+  QVTK_RenderWindowInteractor::keyReleaseEvent(event);
+
+  if(GENERATE_SUIT_EVENTS)
+    emit KeyReleased( event );
 }
 
-  
 //----------------------------------------------------------------------------
-static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
-                            SALOME_Actor* theMapActor, 
-                            SVTK_Actor* theActor)
-{
-  theActor->MapEdge(theMapActor,theMapIndex);
-}
-  
-bool
+void
 SVTK_RenderWindowInteractor
-::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex,
-               SALOME_Actor* theMapActor, 
-               bool hilight, 
-               bool update)
+::contextMenuEvent( QContextMenuEvent* event )
 {
-  return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update);
-}
-  
-void 
-SVTK_RenderWindowInteractor
-::setEdgeData(const int& theCellIndex, 
-             SALOME_Actor* theMapActor,
-             const int& theEdgeIndex, 
-             SVTK_Actor* theActor )
-{
-  TColStd_IndexedMapOfInteger MapIndex; 
-  MapIndex.Add(theCellIndex); 
-  MapIndex.Add(theEdgeIndex);
-  theActor->MapEdge(theMapActor,MapIndex);
+  if( !( event->state() & KeyButtonMask ) )
+    emit contextMenuRequested( event );
 }
index 55b07e806c6478c915a4227817c4b528d3e175a0..bc0020ddf9a447880cad9e208dd97dae40dfd219 100644 (file)
@@ -21,8 +21,8 @@
 //
 //
 //
-//  File   : SVTK_RenderWindowInteractor.h
-//  Author : Nicolas REJNERI
+//  File   : 
+//  Author : 
 //  Module : SALOME
 //  $Header$
 
 #define SVTK_RenderWindowInteractor_h
 
 #include "SVTK.h"
-
 #include "SVTK_Selection.h"
-#include "SALOME_InteractiveObject.hxx"
-
-// QT Includes
-#include <qobject.h>
-#include <qtimer.h>
-
-// VTK Includes
-#include <vtkVersion.h>
-#include <vtkRenderWindowInteractor.h>
-
-// Open CASCADE Includes
-#include <TColStd_MapOfInteger.hxx>
-#include <TColStd_IndexedMapOfInteger.hxx>
-#include <TColStd_MapIteratorOfMapOfInteger.hxx>
-
-class vtkPicker;
-class vtkCellPicker;
-class vtkPointPicker;
-class vtkActorCollection;
-
-class SALOME_Actor;
-class SVTK_Actor;
-
-class SVTK_ViewWindow;
-class SVTK_RenderWindow;
-class SVTK_InteractorStyle;
-
-// ------------------------------------------------------------
-// :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
-// The Signal/Slot mechanism used by Qt requires that QObject 
-// appear as the first class when using multiple inheritance. 
-// Hence the order of the two classes QObject and vtkRenderWindowInteractor
-// matters here. Be careful not to change it by accident. 
-// ------------------------------------------------------------
-class SVTK_EXPORT SVTK_RenderWindowInteractor: public QObject, 
-  public vtkRenderWindowInteractor
+
+#include <vtkSmartPointer.h>
+#include <qwidget.h>
+
+// undefining min and max because CASCADE's defines them and
+// it clashes with std::min(), std::max()
+#undef min
+#undef max
+
+#include <stack>
+
+class vtkGenericRenderWindowInteractor;
+class vtkInteractorStyle;
+class vtkCallbackCommand;
+class vtkRenderWindow;
+class vtkRenderer;
+class vtkObject;
+
+class SVTK_Selector;
+class SVTK_Renderer;
+
+//============================================================================
+//! Implemements Qt based vtkRenderWindowInteractor.
+/*!
+  The class inherits #QWidget class in order to be possible process Qt events.
+  It invokes corresponding VTK events through usage of its device - a #vtkGenericRenderWindowInteractor.
+  Also, it creates, initialize and holds vtkRenderWindow instance.
+*/
+class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget
 {
-  Q_OBJECT ;   
-  friend class SVTK_ViewWindow;
-public:
-
-  static SVTK_RenderWindowInteractor *New() ; 
-
-  vtkTypeMacro(SVTK_RenderWindowInteractor,vtkRenderWindowInteractor);
-
-  // Description:
-  // Initializes the event handlers without an XtAppContext.  This is
-  // good for when you don`t have a user interface, but you still
-  // want to have mouse interaction.
-  virtual void Initialize();
-
-  virtual void SetInteractorStyle(vtkInteractorObserver *);
-  SVTK_InteractorStyle* GetSInteractorStyle(){ return myInteractorStyle;}
-
-  // Description:
-  // This will start up the X event loop and never return. If you
-  // call this method it will loop processing X events until the
-  // application is exited.
-  virtual void Start();
-  
-  // Description:
-  // Event loop notification member for Window size change
-  virtual void UpdateSize(int x,int y);
-
-  // Description:
-  // Timer methods must be overridden by platform dependent subclasses.
-  // flag is passed to indicate if this is first timer set or an update
-  // as Win32 uses repeating timers, whereas X uses One shot more timer
-  // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
-  // otherwise Win32 should exit and X should perform AddTimeOut()
-  virtual int CreateTimer(int ) ; 
-  virtual int DestroyTimer() ; 
-  
-  /* Selection Management */
-  bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex, 
-                    SALOME_Actor* theMapActor, 
-                    bool hilight, 
-                    bool update = true );
-  bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex, 
-                    SALOME_Actor* theMapActor, 
-                    bool hilight, 
-                    bool update = true );
-  bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex, 
-                     SALOME_Actor* theMapActor, 
-                     bool hilight, 
-                     bool update = true );
-  bool highlight(const Handle(SALOME_InteractiveObject)& IObject, 
-                bool hiligth, 
-                bool immediatly = true );
-  void unHighlightSubSelection();
-  bool unHighlightAll();
-
-  bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
-  bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
-  void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
-
-  void SetSelectionMode(Selection_Mode mode);
-  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);
-
-  // Displaymode management
-  int GetDisplayMode();
-  void SetDisplayMode(int);
-
-  // Switch representation wireframe/shading
-  void SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, int theMode);
-
-  // Change all actors to wireframe or surface
-  void ChangeRepresentationToWireframe();
-  void ChangeRepresentationToSurface();
-
-  // Change to wireframe or surface a list of vtkactor
-  void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
-  void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
-
-  // Erase Display functions
-  void EraseAll();
-  void DisplayAll();
-  void RemoveAll( const bool immediatly );
-  void Erase(const Handle(SALOME_InteractiveObject)& IObject, 
-            bool immediatly=true);
-  void Remove(const Handle(SALOME_InteractiveObject)& IObject, 
-             bool immediatly=true);
-  void Display(const Handle(SALOME_InteractiveObject)& IObject, 
-              bool immediatly=true);
-
-  void Display( SALOME_Actor* SActor, 
-               bool immediatly = true );
-  void Erase( SALOME_Actor* SActor, 
-             bool immediatly = true );
-  void Remove( SALOME_Actor* SActor, 
-              bool updateViewer = true );
-
-  // Transparency
-  void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,
-                      float trans);
-  float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
-
-  // Color
-  void SetColor(const Handle(SALOME_InteractiveObject)& IObject,
-               QColor thecolor);
-  QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
-
-  void Update();
-
-  vtkRenderer* GetRenderer();
-
-  void setGUIWindow(QWidget* theWindow);
-
-  void setViewWindow(SVTK_ViewWindow* theViewWindow);
-  
-  void setCellData(const int& theIndex, 
-                  SALOME_Actor* theMapActor,
-                  SVTK_Actor* theActor);
-  void setEdgeData(const int& theCellIndex, 
-                  SALOME_Actor* theMapActor,
-                  const int& theEdgeIndex, 
-                  SVTK_Actor* theActor ); //NB
-  void setPointData(const int& theIndex, 
-                   SALOME_Actor* theMapActor,
-                   SVTK_Actor* theActor);
-
-  typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
-                              SALOME_Actor* theMapActor, 
-                              SVTK_Actor* theActor);
- protected:
+  Q_OBJECT;
 
-  SVTK_RenderWindowInteractor();
-  ~SVTK_RenderWindowInteractor();
+ public:
+  QVTK_RenderWindowInteractor(QWidget* theParent, 
+                             const char* theName);
+
+  ~QVTK_RenderWindowInteractor();
+
+  //! To initialize by #vtkGenericRenderWindowInteractor instance
+  virtual
+  void
+  Initialize(vtkGenericRenderWindowInteractor* theDevice);
 
-  SVTK_InteractorStyle* myInteractorStyle;
-
-  bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex, 
-                SALOME_Actor* theMapActor, 
-                SVTK_Actor* theActor,
-                TUpdateActor theFun, 
-                bool hilight, 
-                bool update);
-  void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
-                   SALOME_Actor* theMapActor,
-                   SVTK_Actor *theActor,
-                   TUpdateActor theFun);
-  
-  // Timer used during various mouse events to figure 
-  // out mouse movements. 
-  QTimer *mTimer ;
-
-  int myDisplayMode;
-
-  //NRI: Selection mode
-  SVTK_Actor* myPointActor;
-  SVTK_Actor* myEdgeActor;
-  SVTK_Actor* myCellActor;
-  void MoveInternalActors();
-
-  vtkPicker* myBasicPicker;
-  vtkCellPicker* myCellPicker;
-  vtkPointPicker* myPointPicker;
-  
-  // User for switching to stereo mode.
-  int PositionBeforeStereo[2];
+  vtkGenericRenderWindowInteractor* 
+  GetDevice();
+
+  vtkRenderWindow*
+  getRenderWindow();
+
+  //! Just to simplify usage of its device (#vtkGenericRenderWindowInteractor)
+  virtual
+  void
+  InvokeEvent(unsigned long theEvent, void* theCallData);
 
  public slots:
-  void MouseMove(const QMouseEvent *event) ;
-  void LeftButtonPressed(const QMouseEvent *event) ;
-  void LeftButtonReleased(const QMouseEvent *event) ;
-  void MiddleButtonPressed(const QMouseEvent *event) ;
-  void MiddleButtonReleased(const QMouseEvent *event) ;
-  void RightButtonPressed(const QMouseEvent *event) ;
-  void RightButtonReleased(const QMouseEvent *event) ;
-  void ButtonPressed(const QMouseEvent *event) ;
-  void ButtonReleased(const QMouseEvent *event) ;
-  void KeyPressed(QKeyEvent *event) ;
-
- private slots:
-  // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
-  // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, 
-  // we have to include all of these for the time being. Once,
-  // this bug in MOC is fixed, we can separate these. 
-  void TimerFunc() ;
+   //! Need for initial contents display on Win32
+  virtual void show();
+
+  //! To implement final initialization, just before the widget is displayed
+  virtual void polish();
 
+  //! To adjust widget and vtkRenderWindow size
+  virtual void resize(int w, int h);
+
+ protected:
+  virtual void paintEvent( QPaintEvent* );
+  virtual void resizeEvent( QResizeEvent* );
+
+  virtual void mouseMoveEvent( QMouseEvent* );
+  virtual void mousePressEvent( QMouseEvent* );
+  virtual void mouseReleaseEvent( QMouseEvent* );
+  virtual void mouseDoubleClickEvent( QMouseEvent* );
+  virtual void wheelEvent( QWheelEvent* );
+  virtual void keyPressEvent( QKeyEvent* );
+  virtual void keyReleaseEvent( QKeyEvent* );
+  virtual void enterEvent( QEvent * );
+  virtual void leaveEvent( QEvent * );
+
+  virtual void contextMenuEvent( QContextMenuEvent * e );
+
+  // reimplemented from QWidget in order to set window - receiver
+  // of space mouse events. 
+  virtual void focusInEvent( QFocusEvent* );
+  virtual void focusOutEvent( QFocusEvent* );
+
+  //! To handle native X11 events (from such devices as SpaceMouse)
+  virtual bool x11Event( XEvent *e );
+
+  vtkSmartPointer<vtkRenderWindow> myRenderWindow;
+  vtkSmartPointer<vtkGenericRenderWindowInteractor> myDevice;
+};
+
+
+//============================================================================
+//! Extends QVTK_RenderWindowInteractor functionality.
+/*!
+  Implements such features as 
+  support of selection, 
+  run-time interactor style management,
+  one render window per one renderer collaboration and
+  SUIT_ViewWindow events invocation.
+*/
+class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor
+{
+  Q_OBJECT;
+
+ public:
+  SVTK_RenderWindowInteractor(QWidget* theParent, 
+                             const char* theName);
+
+  ~SVTK_RenderWindowInteractor();
+
+  //! To initialize properly the class
+  virtual
+  void
+  Initialize(vtkGenericRenderWindowInteractor* theDevice,
+            SVTK_Renderer* theRenderer,
+            SVTK_Selector* theSelector);
+
+  //----------------------------------------------------------------------------
+  //! To get corresponding SVTK_Renderer instance
+  SVTK_Renderer* 
+  GetRenderer();
+
+  //! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
+  vtkRenderer* 
+  getRenderer();
+
+  //----------------------------------------------------------------------------
+  //! To get current interactor style
+  vtkInteractorStyle* 
+  GetInteractorStyle();
+
+  //! To change current interactor style by pushing the new one into the container
+  void
+  PushInteractorStyle(vtkInteractorStyle* theStyle);
+
+  //! To restore previous interactor style
+  void
+  PopInteractorStyle();
+
+  //----------------------------------------------------------------------------
+  //! To get corresponding SVTK_Selector
+  SVTK_Selector* 
+  GetSelector();
+
+  //! To get current selection mode (just to simplify collobaration with SVTK_Selector)
+  Selection_Mode 
+  SelectionMode() const;
+
+  //! To change selection mode (just to simplify collobaration with SVTK_Selector)
+  void 
+  SetSelectionMode(Selection_Mode theMode);
+
+ public:
+  //! To transform vtkCommand::EndPickEvent to Qt selectionChanged signal
+  void
+  onEmitSelectionChanged();
+
+ public:
  signals:
-  void RenderWindowModified() ;
+  void MouseMove( QMouseEvent* );
+  void MouseButtonPressed( QMouseEvent* );
+  void MouseButtonReleased( QMouseEvent* );
+  void MouseDoubleClicked( QMouseEvent* );
+  void ButtonPressed(const QMouseEvent *event);
+  void ButtonReleased(const QMouseEvent *event);
+  void WheelMoved( QWheelEvent* );
+  void KeyPressed( QKeyEvent* );
+  void KeyReleased( QKeyEvent* );
   void contextMenuRequested( QContextMenuEvent *e );
 
- private:
-  SVTK_ViewWindow* myViewWindow;  
-  QWidget* myGUIWindow;  
-  double myTolNodes;
-  double myTolItems;
+  void selectionChanged();
+
+ protected:
+  virtual void mouseMoveEvent( QMouseEvent* );
+  virtual void mousePressEvent( QMouseEvent* );
+  virtual void mouseReleaseEvent( QMouseEvent* );
+  virtual void mouseDoubleClickEvent( QMouseEvent* );
+  virtual void wheelEvent( QWheelEvent* );
+  virtual void keyPressEvent( QKeyEvent* );
+  virtual void keyReleaseEvent( QKeyEvent* );
+  virtual void contextMenuEvent( QContextMenuEvent * e );
+
+  void
+  SetRenderer(SVTK_Renderer *theRenderer);
+
+  void
+  SetSelector(SVTK_Selector* theSelector);
+
+  void
+  InitInteractorStyle(vtkInteractorStyle* theStyle);
+
+  //----------------------------------------------------------------
+  // Main process VTK event method
+  static
+  void
+  ProcessEvents(vtkObject* theObject, 
+               unsigned long theEvent,
+               void* theClientData, 
+               void* theCallData);
+
+  // Used to process VTK events
+  vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
+
+  // Priority at which events are processed
+  float myPriority;
+
+  //----------------------------------------------------------------
+  vtkSmartPointer<SVTK_Selector> mySelector;
+
+  vtkSmartPointer<SVTK_Renderer> myRenderer;
+
+  typedef vtkSmartPointer<vtkInteractorStyle> PInteractorStyle;
+  typedef std::stack<PInteractorStyle> TInteractorStyles;
+  TInteractorStyles myInteractorStyles;
 };
 
 
diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx
new file mode 100644 (file)
index 0000000..cad43a1
--- /dev/null
@@ -0,0 +1,655 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   :
+//  Author :
+//  Module :
+//  $Header$
+
+#include "SVTK_Renderer.h"
+
+#include "SVTK_Trihedron.h"
+#include "SVTK_CubeAxesActor2D.h"
+#include "SVTK_RectPicker.h"
+
+#include "SALOME_Actor.h"
+#include "VTKViewer_Actor.h"
+#include "VTKViewer_Transform.h"
+#include "VTKViewer_Utilities.h"
+
+#include <vtkCamera.h>
+#include <vtkRenderer.h>
+#include <vtkTextProperty.h>
+#include <vtkObjectFactory.h>
+#include <vtkCallbackCommand.h>
+
+#include <vtkPicker.h>
+#include <vtkPointPicker.h>
+#include <vtkCellPicker.h>
+
+#include <vtkProperty.h>
+
+// undefining min and max because CASCADE's defines them and
+// it clashes with std::min(), std::max() included in utilities.h
+#undef min
+#undef max
+
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(SVTK_Renderer);
+
+//----------------------------------------------------------------------------
+SVTK_Renderer
+::SVTK_Renderer():
+  myDevice(vtkRenderer::New()),
+  myInteractor(NULL),
+  myPriority(0.0),
+  myEventCallbackCommand(vtkCallbackCommand::New()),
+  myPointPicker(vtkPointPicker::New()),
+  myCellPicker(vtkCellPicker::New()),
+  myPointRectPicker(SVTK_RectPicker::New()),
+  myCellRectPicker(SVTK_RectPicker::New()),
+  myPreHighlightProperty(vtkProperty::New()),
+  myHighlightProperty(vtkProperty::New()),
+  myTransform(VTKViewer_Transform::New()),
+  myCubeAxes(SVTK_CubeAxesActor2D::New()),
+  myTrihedron(SVTK_Trihedron::New()),
+  myTrihedronSize(105)
+{
+  myDevice->Delete();
+  myTransform->Delete();
+
+  SetSelectionTolerance();
+
+  myPointPicker->Delete();
+  myCellPicker->Delete();
+
+  myPointRectPicker->Delete();
+  myPointRectPicker->PickFromListOn();
+
+  myCellRectPicker->Delete();
+  myCellRectPicker->PickFromListOn();
+  myCellRectPicker->PickPointsOff();
+
+  //SetPreselectionProp();
+  myPreHighlightProperty->Delete();
+  myPreHighlightProperty->SetColor(0,1,1);
+  myPreHighlightProperty->SetPointSize(SALOME_POINT_SIZE+2);
+  myPreHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH+2);
+  myPreHighlightProperty->SetRepresentationToPoints();
+
+  //SetSelectionProp();
+  myHighlightProperty->Delete();
+  myHighlightProperty->SetColor(1,1,0);
+  myHighlightProperty->SetPointSize(SALOME_POINT_SIZE+2);
+  myHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH+2);
+  myHighlightProperty->SetRepresentationToPoints();
+
+  myTrihedron->Delete();
+  myCubeAxes->Delete();
+  myEventCallbackCommand->Delete();
+
+  myTrihedron->AddToRender(GetDevice());
+  GetDevice()->AddProp(GetCubeAxes());
+
+  myBndBox[0] = myBndBox[2] = myBndBox[4] = 0;
+  myBndBox[1] = myBndBox[3] = myBndBox[5] = myTrihedron->GetSize();
+
+  myCubeAxes->SetBounds(myBndBox);
+  myCubeAxes->SetCamera(GetDevice()->GetActiveCamera());
+
+  myCubeAxes->SetLabelFormat("%6.4g");
+  myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
+  myCubeAxes->SetFontFactor(0.8);
+  myCubeAxes->SetCornerOffset(0);
+  myCubeAxes->SetScaling(0);
+  myCubeAxes->SetNumberOfLabels(5);
+  myCubeAxes->VisibilityOff();
+  myCubeAxes->SetTransform(GetTransform());
+
+  vtkTextProperty* aTextProp = vtkTextProperty::New();
+  aTextProp->SetColor(1, 1, 1);
+  aTextProp->ShadowOn();
+  myCubeAxes->SetAxisTitleTextProperty(aTextProp);
+  myCubeAxes->SetAxisLabelTextProperty(aTextProp);
+  aTextProp->Delete();
+
+  GetDevice()->GetActiveCamera()->ParallelProjectionOn();
+  GetDevice()->LightFollowCameraOn();
+  GetDevice()->TwoSidedLightingOn();
+
+  myEventCallbackCommand->SetClientData(this);
+  myEventCallbackCommand->SetCallback(SVTK_Renderer::ProcessEvents);
+  GetDevice()->AddObserver(vtkCommand::ConfigureEvent,
+                          myEventCallbackCommand.GetPointer(), 
+                          myPriority);
+  GetDevice()->AddObserver(vtkCommand::ResetCameraEvent,
+                          myEventCallbackCommand.GetPointer(), 
+                          myPriority);
+  GetDevice()->AddObserver(vtkCommand::ResetCameraClippingRangeEvent,
+                          myEventCallbackCommand.GetPointer(), 
+                          myPriority);
+}
+
+SVTK_Renderer
+::~SVTK_Renderer()
+{
+  vtkActorCollection* anActors = GetDevice()->GetActors();
+  vtkActorCollection* anActors2 = vtkActorCollection::New();
+
+  anActors->InitTraversal();
+  while(vtkActor* anAct = anActors->GetNextActor()){
+    if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct)){
+      anActors2->AddItem(anActor);
+    }
+  }
+
+  anActors2->InitTraversal();
+  while(vtkActor* anAct = anActors2->GetNextActor()){
+    if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct)){
+      RemoveActor(anActor);
+    }
+  }
+
+  anActors2->Delete();
+}
+
+
+void 
+SVTK_Renderer
+::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
+               unsigned long theEvent,
+               void* theClientData, 
+               void* vtkNotUsed(theCallData))
+{
+  SVTK_Renderer* self = reinterpret_cast<SVTK_Renderer*>(theClientData);
+
+  switch(theEvent){
+  case vtkCommand::ConfigureEvent:
+    self->OnResetView();
+    break;
+  case vtkCommand::ResetCameraEvent:
+    self->OnFitAll();
+    break;
+  case vtkCommand::ResetCameraClippingRangeEvent:
+    self->OnResetClippingRange();
+    break;
+  }
+}
+
+//----------------------------------------------------------------------------
+vtkRenderer* 
+SVTK_Renderer
+::GetDevice()
+{
+  return myDevice.GetPointer();
+}
+
+void 
+SVTK_Renderer
+::Initialize(vtkRenderWindowInteractor* theInteractor,
+            SVTK_Selector* theSelector)
+{
+  myInteractor = theInteractor;
+  mySelector = theSelector;
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::AddActor(VTKViewer_Actor* theActor)
+{
+  if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(theActor)){
+    anActor->SetInteractor(myInteractor);
+    anActor->SetTransform(GetTransform());
+    anActor->SetSelector(mySelector.GetPointer());
+
+    anActor->SetPointPicker(myPointPicker.GetPointer());
+    anActor->SetCellPicker(myCellPicker.GetPointer());
+
+    anActor->SetPointRectPicker(myPointRectPicker.GetPointer());
+    anActor->SetCellRectPicker(myCellRectPicker.GetPointer());
+
+    anActor->SetPreHighlightProperty(myPreHighlightProperty.GetPointer());
+    anActor->SetHighlightProperty(myHighlightProperty.GetPointer());
+
+    anActor->AddToRender(GetDevice());
+    AdjustActors();
+  }
+}
+
+void
+SVTK_Renderer
+::RemoveActor(VTKViewer_Actor* theActor)
+{
+  if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(theActor)){
+    // Order of the calls are important because VTKViewer_Actor::RemoveFromRender
+    //   can leads do destruction of the actor
+    anActor->SetInteractor(NULL);
+    anActor->SetTransform(NULL);
+    anActor->SetSelector(NULL);
+
+    anActor->SetPointPicker(NULL);
+    anActor->SetCellPicker(NULL);
+
+    anActor->SetPointRectPicker(NULL);
+    anActor->SetCellRectPicker(NULL);
+
+    anActor->SetPreHighlightProperty(NULL);
+    anActor->SetHighlightProperty(NULL);
+
+    anActor->RemoveFromRender(GetDevice());
+    AdjustActors();
+  }
+}
+
+VTKViewer_Transform* 
+SVTK_Renderer
+::GetTransform()
+{
+  return myTransform.GetPointer();
+}
+
+void
+SVTK_Renderer
+::GetScale( double theScale[3] ) 
+{
+  myTransform->GetMatrixScale( theScale );
+}
+
+void
+SVTK_Renderer
+::SetScale( double theScale[3] ) 
+{
+  myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
+  AdjustActors();
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::SetSelectionProp(const double& theRed, 
+                  const double& theGreen, 
+                  const double& theBlue, 
+                  const int& theWidth) 
+{
+  myHighlightProperty->SetColor( theRed, theGreen, theBlue );
+  myHighlightProperty->SetLineWidth( theWidth );
+  myHighlightProperty->SetPointSize( theWidth );
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::SetPreselectionProp(const double& theRed, 
+                     const double& theGreen, 
+                     const double& theBlue, 
+                     const int& theWidth) 
+{
+  myPreHighlightProperty->SetColor( theRed, theGreen, theBlue );
+  myPreHighlightProperty->SetLineWidth( theWidth );
+  myPreHighlightProperty->SetPointSize( theWidth );
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::SetSelectionTolerance(const double& theTolNodes, 
+                       const double& theTolCell)
+{
+  myPointPicker->SetTolerance( theTolNodes );
+  myCellPicker->SetTolerance( theTolCell );
+
+  myPointRectPicker->SetTolerance( theTolNodes );
+  myCellRectPicker->SetTolerance( theTolCell );
+}
+
+
+//----------------------------------------------------------------------------
+/*! If parameter theIsForcedUpdate is true, recalculate parameters for
+ *  trihedron and cube axes, even if trihedron and cube axes is invisible.
+ */
+
+inline
+bool
+CheckBndBox(const float theBounds[6])
+{
+  if(theBounds[0] > -VTK_LARGE_FLOAT && theBounds[1] < VTK_LARGE_FLOAT &&
+     theBounds[2] > -VTK_LARGE_FLOAT && theBounds[3] < VTK_LARGE_FLOAT &&
+     theBounds[4] > -VTK_LARGE_FLOAT && theBounds[5] < VTK_LARGE_FLOAT)
+    return true;
+  return false;
+}
+
+bool
+SVTK_Renderer
+::OnAdjustActors()
+{
+  bool aTDisplayed = IsTrihedronDisplayed();
+  bool aCDisplayed = IsCubeAxesDisplayed();
+
+  float aNewBndBox[6];
+  aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT;
+  aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT;
+
+  int aVisibleNum = myTrihedron->GetVisibleActorCount(GetDevice());
+  if(aVisibleNum){
+    if(aTDisplayed)
+      myTrihedron->VisibilityOff();
+
+    if(aCDisplayed) 
+      myCubeAxes->VisibilityOff();
+
+    // if the new trihedron size have sufficient difference, then apply the value
+    double aSize = myTrihedron->GetSize();
+    ComputeTrihedronSize(GetDevice(),aSize,aSize,myTrihedronSize);
+    myTrihedron->SetSize(aSize);
+
+    // iterate through displayed objects and set size if necessary
+    vtkActorCollection* anActors = GetDevice()->GetActors();
+    anActors->InitTraversal();
+    while(vtkActor* anAct = anActors->GetNextActor()){
+      if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct)){
+       if(anActor->IsResizable())
+         anActor->SetSize(0.5*aSize);
+        if(anActor->GetVisibility() && !anActor->IsInfinitive()){
+         float *aBounds = anActor->GetBounds();
+          if(CheckBndBox(aBounds))
+           for(int i = 0; i < 5; i = i + 2){
+             if(aBounds[i] < aNewBndBox[i]) 
+               aNewBndBox[i] = aBounds[i];
+             if(aBounds[i+1] > aNewBndBox[i+1]) 
+               aNewBndBox[i+1] = aBounds[i+1];
+           }
+        }
+      }
+    }
+
+    if(aTDisplayed) 
+      myTrihedron->VisibilityOn();
+
+    if(aCDisplayed) 
+      myCubeAxes->VisibilityOn();
+    
+  }else{
+    double aSize = myTrihedron->GetSize();
+    aNewBndBox[0] = aNewBndBox[2] = aNewBndBox[4] = 0;
+    aNewBndBox[1] = aNewBndBox[3] = aNewBndBox[5] = aSize;
+  }
+  
+  if(CheckBndBox(aNewBndBox)){
+    for(int i = 0; i < 6; i++)
+      myBndBox[i] = aNewBndBox[i];
+    myCubeAxes->SetBounds(myBndBox);
+    return true;
+  }
+
+  return false;
+}
+
+void
+SVTK_Renderer
+::AdjustActors()
+{
+  if(OnAdjustActors())
+    ::ResetCameraClippingRange(GetDevice());
+}
+
+void
+SVTK_Renderer
+::SetTrihedronSize(int theSize)
+{
+  if(myTrihedronSize != theSize){
+    myTrihedronSize = theSize;
+    AdjustActors();
+  }
+}
+
+int
+SVTK_Renderer
+::GetTrihedronSize() const
+{
+  return myTrihedronSize;
+}
+
+
+//----------------------------------------------------------------------------
+VTKViewer_Trihedron* 
+SVTK_Renderer
+::GetTrihedron()
+{
+  return myTrihedron.GetPointer();
+}
+
+bool
+SVTK_Renderer
+::IsTrihedronDisplayed()
+{
+  return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+}
+
+void 
+SVTK_Renderer
+::OnViewTrihedron()
+{
+  if(IsTrihedronDisplayed())
+    myTrihedron->VisibilityOff();
+  else
+    myTrihedron->VisibilityOn();
+}
+
+void
+SVTK_Renderer
+::OnAdjustTrihedron()
+{   
+  AdjustActors();
+}
+
+
+//----------------------------------------------------------------------------
+SVTK_CubeAxesActor2D* 
+SVTK_Renderer
+::GetCubeAxes()
+{
+  return myCubeAxes.GetPointer();
+}
+
+bool
+SVTK_Renderer
+::IsCubeAxesDisplayed()
+{
+  return myCubeAxes->GetVisibility() == 1;
+}
+
+void
+SVTK_Renderer
+::OnViewCubeAxes()
+{
+  if(IsCubeAxesDisplayed())
+    myCubeAxes->VisibilityOff();
+  else
+    myCubeAxes->VisibilityOn();
+}
+
+void
+SVTK_Renderer
+::OnAdjustCubeAxes()
+{   
+  AdjustActors();
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnResetView()
+{
+  int aTrihedronIsVisible = IsTrihedronDisplayed();
+  int aCubeAxesIsVisible = IsCubeAxesDisplayed();
+
+  myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
+  myCubeAxes->SetVisibility(0);
+
+  ::ResetCamera(GetDevice(),true);  
+  vtkCamera* aCamera = GetDevice()->GetActiveCamera();
+  aCamera->SetPosition(1,-1,1);
+  aCamera->SetViewUp(0,0,1);
+  ::ResetCamera(GetDevice(),true);  
+
+  if(aTrihedronIsVisible) 
+    myTrihedron->VisibilityOn();
+  else
+    myTrihedron->VisibilityOff();
+
+  if(aCubeAxesIsVisible) 
+    myCubeAxes->VisibilityOn();
+  else
+    myCubeAxes->VisibilityOff();
+
+  static float aCoeff = 3.0;
+  aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnFitAll()
+{
+  int aTrihedronWasVisible = false;
+  int aCubeAxesWasVisible = false;
+
+  aTrihedronWasVisible = IsTrihedronDisplayed();
+  if(aTrihedronWasVisible)
+    myTrihedron->VisibilityOff();
+
+  aCubeAxesWasVisible = IsCubeAxesDisplayed();
+  if(aCubeAxesWasVisible)
+    myCubeAxes->VisibilityOff();
+
+  if(myTrihedron->GetVisibleActorCount(GetDevice())){
+    myTrihedron->VisibilityOff();
+    myCubeAxes->VisibilityOff();
+    ::ResetCamera(GetDevice());
+  }else{
+    myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+    myCubeAxes->SetVisibility(2);
+    ::ResetCamera(GetDevice(),true);
+  }
+
+  if(aTrihedronWasVisible)
+    myTrihedron->VisibilityOn();
+  else
+    myTrihedron->VisibilityOff();
+  
+  if(aCubeAxesWasVisible)
+    myCubeAxes->VisibilityOn();
+  else
+    myCubeAxes->VisibilityOff();
+
+  ::ResetCameraClippingRange(GetDevice());
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnResetClippingRange()
+{
+  return;
+  ::ResetCameraClippingRange(GetDevice());
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnFrontView()
+{
+  vtkCamera* aCamera = GetDevice()->GetActiveCamera();
+  aCamera->SetPosition(1,0,0);
+  aCamera->SetViewUp(0,0,1);
+  aCamera->SetFocalPoint(0,0,0);
+  this->OnFitAll();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnBackView()
+{
+  vtkCamera* aCamera = GetDevice()->GetActiveCamera();
+  aCamera->SetPosition(-1,0,0);
+  aCamera->SetViewUp(0,0,1);
+  aCamera->SetFocalPoint(0,0,0);
+  this->OnFitAll();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnTopView()
+{
+  vtkCamera* aCamera = GetDevice()->GetActiveCamera();
+  aCamera->SetPosition(0,0,1);
+  aCamera->SetViewUp(0,1,0);
+  aCamera->SetFocalPoint(0,0,0);
+  this->OnFitAll();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnBottomView()
+{
+  vtkCamera* aCamera = GetDevice()->GetActiveCamera();
+  aCamera->SetPosition(0,0,-1);
+  aCamera->SetViewUp(0,1,0);
+  aCamera->SetFocalPoint(0,0,0);
+  this->OnFitAll();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnLeftView()
+{
+  vtkCamera* aCamera = GetDevice()->GetActiveCamera(); 
+  aCamera->SetPosition(0,-1,0);
+  aCamera->SetViewUp(0,0,1);
+  aCamera->SetFocalPoint(0,0,0);
+  this->OnFitAll();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_Renderer
+::OnRightView()
+{
+  vtkCamera* aCamera = GetDevice()->GetActiveCamera();
+  aCamera->SetPosition(0,1,0);
+  aCamera->SetViewUp(0,0,1);
+  aCamera->SetFocalPoint(0,0,0);
+  this->OnFitAll();
+}
diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h
new file mode 100644 (file)
index 0000000..5f48654
--- /dev/null
@@ -0,0 +1,245 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#ifndef SVTK_Renderer_h
+#define SVTK_Renderer_h
+
+#include "SVTK.h"
+
+#include <vtkObject.h>
+#include <vtkSmartPointer.h>
+
+class vtkRenderer;
+class vtkCallbackCommand;
+class vtkRenderWindowInteractor;
+
+class vtkPicker;
+class vtkPointPicker;
+class vtkCellPicker;
+class vtkProperty;
+
+class SVTK_RectPicker;
+
+class VTKViewer_Trihedron;
+class VTKViewer_Transform;
+class SVTK_CubeAxesActor2D;
+class VTKViewer_Actor;
+class SVTK_Selector;
+
+
+//! The class is a container for #vtkRenderer instance.
+/*!
+  Main goal of the class is to apply common behaviour to all #SALOME_Actor, like
+  selection and preselection colors.
+  Also, the class is responsible for management of internal actors like trihedron an so on.
+ */
+//============================================================================
+class SVTK_EXPORT SVTK_Renderer : public vtkObject
+{
+ public:
+  vtkTypeMacro(SVTK_Renderer,vtkObject);
+  static SVTK_Renderer* New();
+
+  //----------------------------------------------------------------------------
+  //! Get its device
+  vtkRenderer* 
+  GetDevice();
+
+  //! Initialize the class
+  virtual
+  void 
+  Initialize(vtkRenderWindowInteractor* theInteractor,
+            SVTK_Selector* theSelector);
+
+  //----------------------------------------------------------------------------
+  //! This method publishes pointed actor into the renderer
+  virtual
+  void 
+  AddActor(VTKViewer_Actor* theActor);
+
+  //! This method removes pointed actor from the renderer
+  virtual
+  void 
+  RemoveActor(VTKViewer_Actor* theActor);
+
+  //! Get special container that keeps scaling of the scene 
+  VTKViewer_Transform* 
+  GetTransform();
+
+  //! This method allow to apply a scale on the whole scene
+  virtual
+  void
+  SetScale( double theScale[3] );
+
+  //! This method allow to get a scale that is applied on the whole scene
+  void
+  GetScale( double theScale[3] );
+
+  //----------------------------------------------------------------------------
+  //! Applies color and size (PointSize and LineWidth) of primitives in selection mode
+  void
+  SetSelectionProp(const double& theRed = 1, 
+                  const double& theGreen = 1,
+                  const double& theBlue = 0, 
+                  const int& theWidth = 5);
+
+  //! Applies color and size (PointSize and LineWidth) of primitives in preselection mode
+  void
+  SetPreselectionProp(const double& theRed = 0, 
+                     const double& theGreen = 1,
+                     const double& theBlue = 1, 
+                     const int& theWidth = 5);
+
+  //! Setup requested tollerance for the picking
+  void
+  SetSelectionTolerance(const double& theTolNodes = 0.025, 
+                       const double& theTolCell = 0.001);
+
+  //----------------------------------------------------------------------------
+  //! Adjust all intenal actors (trihedron and graduated rules) to the scene
+  void
+  AdjustActors();
+
+  //! Set size of the trihedron in percents from bounding box of the scene
+  void
+  SetTrihedronSize(int theSize);
+  //! Get size of the trihedron in percents from bounding box of the scene
+  int  
+  GetTrihedronSize() const;
+
+  //----------------------------------------------------------------------------
+  //! Get trihedron control
+  VTKViewer_Trihedron* 
+  GetTrihedron();
+
+  //! Is trihedron displayed
+  bool 
+  IsTrihedronDisplayed();
+
+  //! Toggle trihedron visibility
+  void 
+  OnViewTrihedron(); 
+
+  //! Adjust size of the trihedron to the bounding box of the scene
+  void 
+  OnAdjustTrihedron();
+
+  //----------------------------------------------------------------------------
+  //! Get graduated rules control
+  SVTK_CubeAxesActor2D* 
+  GetCubeAxes();
+
+  //! Is graduated rules displayed
+  bool 
+  IsCubeAxesDisplayed();
+
+  //! Toggle graduated rules visibility
+  void 
+  OnViewCubeAxes();
+
+  //! Adjust size of the graduated rules to the bounding box of the scene
+  void 
+  OnAdjustCubeAxes();
+
+  //----------------------------------------------------------------------------
+  //! Fit all presentation in the scene into the window
+  void OnFitAll(); 
+  
+  //! Set camera into predefined state
+  void OnResetView(); 
+
+  //! Reset camera clipping range to adjust the range to the bounding box of the scene
+  void OnResetClippingRange(); 
+
+  //! To reset direction of the camera to front view
+  void OnFrontView(); 
+
+  //! To reset direction of the camera to back view
+  void OnBackView(); 
+
+  //! To reset direction of the camera to top view
+  void OnTopView();
+
+  //! To reset direction of the camera to bottom view
+  void OnBottomView();
+
+  //! To reset direction of the camera to right view
+  void OnRightView(); 
+
+  //! To reset direction of the camera to left view
+  void OnLeftView();     
+
+ protected:
+  SVTK_Renderer();
+  ~SVTK_Renderer();
+
+  virtual
+  bool
+  OnAdjustActors();
+
+  //----------------------------------------------------------------------------
+  // Priority at which events are processed
+  float myPriority;
+
+  // Used to process events
+  vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
+
+  // Description:
+  // Main process event method
+  static void ProcessEvents(vtkObject* object, 
+                            unsigned long event,
+                            void* clientdata, 
+                            void* calldata);
+  
+  vtkSmartPointer<vtkRenderer> myDevice;
+  vtkRenderWindowInteractor* myInteractor;
+  vtkSmartPointer<SVTK_Selector> mySelector;
+
+  //----------------------------------------------------------------------------
+  vtkSmartPointer<VTKViewer_Transform> myTransform;
+
+  //----------------------------------------------------------------------------
+  // Highlight/ Prehighlight devices
+  vtkSmartPointer<vtkPointPicker> myPointPicker;
+  vtkSmartPointer<vtkCellPicker> myCellPicker;
+
+  vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
+  vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
+
+  vtkSmartPointer<vtkProperty> myPreHighlightProperty;
+  vtkSmartPointer<vtkProperty> myHighlightProperty;
+
+  //----------------------------------------------------------------------------
+  vtkSmartPointer<SVTK_CubeAxesActor2D> myCubeAxes;
+  vtkSmartPointer<VTKViewer_Trihedron> myTrihedron;  
+  int myTrihedronSize;
+  float myBndBox[6];
+};
+
+#endif
index ef5e662c67c91f5df5d72153ad128a80a3f67241..3307565c24959beb09f32d00e6a177902e4c09b6 100644 (file)
 #define SVTK_SELECTION_H
 
 
-enum Selection_Mode 
-{ 
-  NodeSelection, 
-  CellSelection,
-  EdgeOfCellSelection,
-  EdgeSelection, 
-  FaceSelection, 
-  VolumeSelection, 
-  ActorSelection 
-};
+//! It is possible to introduce new type of selection 
+typedef int Selection_Mode; 
+
+const Selection_Mode NodeSelection = 0;
+const Selection_Mode CellSelection = 1;
+const Selection_Mode EdgeOfCellSelection = 2;
+const Selection_Mode EdgeSelection = 3;
+const Selection_Mode FaceSelection = 4;
+const Selection_Mode VolumeSelection = 5;
+const Selection_Mode ActorSelection = 6;
 
 
 #endif
diff --git a/src/SVTK/SVTK_SelectionEvent.h b/src/SVTK/SVTK_SelectionEvent.h
new file mode 100644 (file)
index 0000000..cfa753f
--- /dev/null
@@ -0,0 +1,55 @@
+//  SALOME SALOMEGUI : implementation of desktop and GUI kernel
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SVTK_SelectionEvent.h
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#ifndef SVTK_SELECTIONEVENT_H
+#define SVTK_SELECTIONEVENT_H
+
+#include "SVTK_Selection.h"
+
+//! The structure is used for passing all infromation necessary for claculation of the selection.
+/*!
+  The SVTK_SelectionEvent is generated by #SVTK_InteractorStyle.
+  In its turn the #SVTK_InteractorStyle uses for it generation #vtkRenderWindowInteractor and
+  #SVTK_Selector instances.
+ */
+struct SVTK_SelectionEvent
+{
+  //! Through usage of the parameter any new type of selection can be introduced
+  Selection_Mode mySelectionMode; 
+  int myX; //!< Current X position of the mouse
+  int myY; //!< Current Y position of the mouse
+  int myLastX; //!< Last X position of the mouse before starting any complex operation (like rectangle selection)
+  int myLastY; //!< Last Y position of the mouse before starting any complex operation
+  bool myIsRectangle; //!< A flag to define is it necessary provide rectangle selection for current #Selection_Mode
+  bool myIsCtrl; //!< Is Ctrl key are pressed
+  bool myIsShift; //!< Is Shift key are pressed
+  int myKeyCode; //!< Code of the pressed key
+  int myRepeatCount; //!< Number of repetion of the key pressing
+};
+
+#endif
index 471c3b8ec5924bf3595d0e0b848a46789ef1e14d..bc6dad1480e5ee99953a82b0e9588e0dba014f5b 100644 (file)
 //  $Header$
 
 
+#include "SVTK_SelectorDef.h"
+
+#include "SALOME_Actor.h"
+
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
 
+#include <vtkCallbackCommand.h>
 
-#include "SALOME_Actor.h"
-#include "SVTK_ViewModel.h"
-#include "SVTK_ViewWindow.h"
-
-#include "SVTK_SelectorDef.h"
+SVTK_Selector* 
+SVTK_Selector
+::New()
+{
+  return new SVTK_SelectorDef();
+}
 
+//----------------------------------------------------------------------------
 SVTK_SelectorDef
 ::SVTK_SelectorDef()
 {
+  mySelectionMode = ActorSelection;
 }
 
 SVTK_SelectorDef
@@ -47,11 +55,32 @@ SVTK_SelectorDef
 {
 }
 
+//----------------------------------------------------------------------------
+void 
+SVTK_SelectorDef
+::StartPickCallback()
+{
+  this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
+}
+
+//----------------------------------------------------------------------------
+void 
+SVTK_SelectorDef
+::EndPickCallback()
+{
+  this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
+}
+
+//----------------------------------------------------------------------------
 void 
 SVTK_SelectorDef
 ::SetSelectionMode(Selection_Mode theMode)
 {
-  mySelectionMode = theMode;
+  if(mySelectionMode != theMode){
+    mySelectionMode = theMode;
+    myMapIOSubIndex.clear();
+    this->EndPickCallback();
+  }
 }
 
 void 
@@ -68,7 +97,7 @@ bool
 SVTK_SelectorDef
 ::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const
 {
-  return myIObjects.find(theIO) != myIObjects.end();
+  return !theIO.IsNull() && (myIObjects.find(theIO) != myIObjects.end());
 }
 
 bool
@@ -333,3 +362,59 @@ SVTK_SelectorDef
 {
   myMapIOSubIndex.clear();  
 }
+
+//----------------------------------------------------------------------------
+void
+SVTK_SelectorDef
+::SetFilter(const Handle(VTKViewer_Filter)& theFilter)
+{
+  myFilters.insert(TFilters::value_type(theFilter->GetId(),theFilter));
+}
+
+//----------------------------------------------------------------------------
+bool
+SVTK_SelectorDef
+::IsFilterPresent(const TFilterID theId) const
+{
+  return myFilters.find(theId) != myFilters.end();
+}
+
+//----------------------------------------------------------------------------
+void  
+SVTK_SelectorDef
+::RemoveFilter(const TFilterID theId)
+{
+  if(IsFilterPresent(theId))
+    myFilters.erase(theId);
+}
+
+//----------------------------------------------------------------------------
+bool
+SVTK_SelectorDef
+::IsValid(SALOME_Actor* theActor,
+         const TFilterID theId,
+         const bool theIsNode) const
+{
+  TFilters::const_iterator anIter = myFilters.begin();
+  for(; anIter != myFilters.end(); ++anIter){
+    const Handle(VTKViewer_Filter)& aFilter = anIter->second;
+    if(theIsNode == aFilter->IsNodeFilter() &&
+       !aFilter->IsValid(theActor,theId))
+      return false;
+  }
+  return true;
+}
+
+//----------------------------------------------------------------------------
+Handle(VTKViewer_Filter) 
+SVTK_SelectorDef
+::GetFilter(const TFilterID theId) const
+{
+  TFilters::const_iterator anIter = myFilters.find(theId);
+  if(anIter != myFilters.end()){
+    const Handle(VTKViewer_Filter)& aFilter = anIter->second;
+    return aFilter;
+  }
+  return Handle(VTKViewer_Filter)();
+}
+
index 26150b4f4df3d5c9a9e1da6b0b32e8ee4629b52f..37ec0acb1bfd178dff36b3f19bb905d7142a0c0c 100644 (file)
 #ifndef SVTK_SELECTOR_H
 #define SVTK_SELECTOR_H
 
+#include "SVTK_Selection.h"
+#include "SALOME_ListIO.hxx"
+#include "VTKViewer_Filter.h"
+#include "SALOME_InteractiveObject.hxx"
+
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
 
-#include "SVTK_Selection.h"
-#include "SALOME_ListIO.hxx"
+#include <vtkObject.h>
 
 class SALOME_Actor;
 
-class SVTK_Selector
+//! Define an abstract interface for selection in SVTK package
+/*!
+  The class implements selection functionality through storing corresponding
+  references to #SALOME_InteractiveObject. For implementation of subselection
+  modes it keeps a corresponding map of sub indexes.
+  \note
+  Also, for each #SALOME_InteractiveObject it tries to keep corresponding refenrence to #SALOME_Actor
+ */
+class SVTK_Selector: public vtkObject
 {
 public:
-  virtual ~SVTK_Selector() {};
+  static SVTK_Selector* New();
+  
+  vtkTypeMacro(SVTK_Selector,vtkObject);
 
+  //! To change current Selection_Mode (as outside effect, it invokes selectionChange signal)
   virtual
   void 
-  SetSelectionMode( Selection_Mode theMode ) = 0;
+  SetSelectionMode(Selection_Mode theMode) = 0;
 
+  //! Get current Selection_Mode
   virtual
   Selection_Mode
   SelectionMode() const = 0;
 
+  //! Clear selection
   virtual
   void
   ClearIObjects() = 0;
 
+  //! Try to find corresponding #SALOME_Actor for given reference on #SALOME_InteractiveObject
   virtual
   SALOME_Actor* 
   GetActor(const Handle(SALOME_InteractiveObject)& theIO) const = 0;
 
+  //! Check, is the #SALOME_InteractiveObject is present into selection
   virtual
   bool
   IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const = 0;
 
+  //! Check, is the #SALOME_Actor is present into selection
   virtual
   bool
   IsSelected(SALOME_Actor* theActor) const = 0;
 
+  //! Modify the selection by adding new reference on #SALOME_InteractiveObject
   virtual
   bool
   AddIObject(const Handle(SALOME_InteractiveObject)& theIO) = 0;
 
+  //! Modify the selection by adding new reference on #SALOME_Actor
   virtual
   bool
   AddIObject(SALOME_Actor* theActor) = 0;
 
+  //! Modify the selection by removing a reference on #SALOME_InteractiveObject
   virtual
   bool 
   RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO) = 0;
 
+  //! Modify the selection by removing a reference on #SALOME_Actor
   virtual
   bool 
   RemoveIObject(SALOME_Actor* theActor) = 0;
 
+  //! Get all #SALOME_InteractiveObject references that is present into selection
   virtual
   const SALOME_ListIO& 
   StoredIObjects() const = 0;
 
+  //! Get number of selected objects
   virtual
   int 
   IObjectCount() const = 0;
 
+  //! Check, if the #SALOME_InteractiveObject has a subselection
   virtual
   bool 
   HasIndex(const Handle(SALOME_InteractiveObject)& theIO ) const = 0;
 
+  //! Get indexes of subslection for given #SALOME_InteractiveObject
   virtual
   void 
   GetIndex( const Handle(SALOME_InteractiveObject)& theIO, 
            TColStd_IndexedMapOfInteger& theIndex ) = 0;
        
+  //! Change indexes of subslection for given #SALOME_InteractiveObject
   virtual
   bool 
   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
                    const TColStd_IndexedMapOfInteger& theIndices, 
                    bool theIsModeShift) = 0;
+
+  //! Change indexes of subslection for given #SALOME_InteractiveObject
   virtual
   bool 
   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
                    const TColStd_MapOfInteger& theIndices, 
                    bool theIsModeShift) = 0;
+
+  //! Change index of subslection for given #SALOME_InteractiveObject
   virtual
   bool
   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
                    int theIndex, 
                    bool theIsModeShift) = 0;
+
+  //! Change index of subslection for given #SALOME_InteractiveObject
   virtual
   void 
   RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, 
               int theIndex) = 0;
+
+  //! Check, if the given index is present in subslection 
   virtual
   bool 
   IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO, 
                  int theIndex) const = 0;
+
+  //! Clear subselection
   virtual
   void 
   ClearIndex() = 0;
+
+  //----------------------------------------------------------------------------
+  typedef int TFilterID;
+
+  //! To apply a filter on the selection
+  virtual
+  void 
+  SetFilter(const Handle(VTKViewer_Filter)& theFilter) = 0;
+
+  //! To get a section filter by its number
+  virtual
+  Handle(VTKViewer_Filter) 
+  GetFilter(const TFilterID theId) const = 0;
+
+  //! Check, if a filter with given number is applyed
+  virtual
+  bool
+  IsFilterPresent(const TFilterID theId) const = 0;
+
+  //! To remove a filter from the selection
+  virtual
+  void
+  RemoveFilter(const TFilterID theId) = 0;
+
+  //! Check, if the index satisfy to the installed filters
+  virtual
+  bool
+  IsValid(SALOME_Actor* theActor,
+         const int theId,
+         const bool theIsNode = false) const = 0;
+  
+  //----------------------------------------------------------------------------
+  virtual
+  void 
+  StartPickCallback() = 0;
+
+  //! To invoke selectionChanged signals
+  virtual
+  void 
+  EndPickCallback() = 0;
 };
 
 
index 47f593e9a3b438ee3bd533b4affe93f653d34846..050a6838a3fd15d48c442c9b2b494778e1482e3a 100644 (file)
@@ -51,7 +51,7 @@ public:
 
   virtual
   void 
-  SetSelectionMode( Selection_Mode theMode );
+  SetSelectionMode(Selection_Mode theMode);
 
   virtual
   Selection_Mode
@@ -133,8 +133,40 @@ public:
   void 
   ClearIndex();
 
+  //----------------------------------------------------------------------------
+  virtual
+  void 
+  SetFilter(const Handle(VTKViewer_Filter)& theFilter);
+
+  virtual
+  Handle(VTKViewer_Filter) 
+  GetFilter(const TFilterID theId) const;
+
+  virtual
+  bool
+  IsFilterPresent(const TFilterID theId) const;
+
+  virtual
+  void
+  RemoveFilter(const int theId);
+
+  virtual
+  bool
+  IsValid(SALOME_Actor* theActor,
+         const TFilterID theId,
+         const bool theIsNode = false) const;
+  
+  //----------------------------------------------------------------------------
+  virtual
+  void 
+  StartPickCallback();
+
+  virtual
+  void 
+  EndPickCallback();
+
 private:
-  Selection_Mode mySelectionMode;
+  int mySelectionMode;
 
   struct TIOLessThan
   {
@@ -146,7 +178,8 @@ private:
     }
   };
 
-  struct TIndexedMapOfInteger{
+  struct TIndexedMapOfInteger
+  {
     TColStd_IndexedMapOfInteger myMap;
     TIndexedMapOfInteger()
     {}
@@ -170,7 +203,9 @@ private:
                    TIndexedMapOfInteger,
                    TIOLessThan> TMapIOSubIndex;
   TMapIOSubIndex myMapIOSubIndex;
-};
 
+  typedef std::map<TFilterID,Handle(VTKViewer_Filter)> TFilters;
+  TFilters myFilters;
+};
 
 #endif
diff --git a/src/SVTK/SVTK_SpaceMouse.cxx b/src/SVTK/SVTK_SpaceMouse.cxx
new file mode 100644 (file)
index 0000000..620e97e
--- /dev/null
@@ -0,0 +1,196 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SVTK_SpaceMouse.cxx
+//  Author : Alexander SLADKOV
+//  Module : SALOME
+//  $Header$
+
+#include <string.h>
+#include <math.h>
+#include <stdio.h>
+
+#include <X11/X.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <X11/keysym.h>
+
+#include "SVTK_SpaceMouse.h"
+
+//---------------------------------------------
+SVTK_SpaceMouse* SVTK_SpaceMouse::myInstance = 0;
+
+//---------------------------------------------
+SVTK_SpaceMouse* SVTK_SpaceMouse::getInstance()
+{
+  if ( !myInstance )
+    myInstance = new SVTK_SpaceMouse();
+  return myInstance;
+}
+
+//---------------------------------------------
+SVTK_SpaceMouse::SVTK_SpaceMouse()
+{
+  win = InputFocus;
+  spaceMouseOn = 0;
+}
+
+//---------------------------------------------
+int SVTK_SpaceMouse::initialize( Display *display, Window window )
+{
+ XMotionEvent        = XInternAtom( display, "MotionEvent",        1 );
+ XButtonPressEvent   = XInternAtom( display, "ButtonPressEvent",   1 );
+ XButtonReleaseEvent = XInternAtom( display, "ButtonReleaseEvent", 1 );
+ XCommandEvent       = XInternAtom( display, "CommandEvent",       1 );
+
+ spaceMouseOn = (XMotionEvent        != 0) && 
+                (XButtonPressEvent   != 0) && 
+                (XButtonReleaseEvent != 0) && 
+                (XCommandEvent       != 0);
+ if ( !spaceMouseOn )
+  return 0;
+
+ spaceMouseOn = setWindow( display, window );
+ if ( !spaceMouseOn )
+  return 0;
+ return spaceMouseOn; 
+}
+
+//---------------------------------------------
+static int errorCallback( Display *display, XErrorEvent *Error )
+{
+  char msg[ 128 ];
+  if ( Error->error_code != BadWindow ) {
+    XGetErrorText( display,Error->error_code,msg,sizeof( msg ) );
+    fprintf( stderr, "SpaceMouse reported error = %s. Exit ... \n", msg );
+  }
+  return 0;
+}
+
+//---------------------------------------------
+int SVTK_SpaceMouse::setWindow( Display *display, Window window )
+{
+  XTextProperty winName;
+  XEvent xEvent;
+  Atom type;
+  int format;
+  unsigned long NItems, BytesReturn;
+  unsigned char *PropReturn;
+  Window root;
+  int result;
+  int (*errorHandler)(Display *,XErrorEvent *);
+
+  result = 1;
+  errorHandler = XSetErrorHandler( errorCallback );
+  root = RootWindow( display, DefaultScreen(display) );
+
+  PropReturn = NULL;
+  XGetWindowProperty( display, root, XCommandEvent, 0,1, 0,
+                     AnyPropertyType, &type, &format, &NItems,
+                     &BytesReturn, &PropReturn );
+
+  win = InputFocus;
+  if ( PropReturn != NULL ) {
+    win = *(Window *) PropReturn;
+    XFree( PropReturn );
+  }
+  else
+    return result = 0;
+
+  if ( XGetWMName( display, win, &winName ) == 0 )
+    return result = 0;
+
+  if ( strcmp( (char *) "Magellan Window", (char *) winName.value) != 0 )
+    return result = 0;
+
+  xEvent.type = ClientMessage;
+  xEvent.xclient.format = 16;
+  xEvent.xclient.send_event = 0;
+  xEvent.xclient.display = display;
+  xEvent.xclient.window = win;
+  xEvent.xclient.message_type = XCommandEvent;
+  
+  xEvent.xclient.data.s[0] = (short) ((window>>16)&0x0000FFFF);
+  xEvent.xclient.data.s[1] = (short)  (window&0x0000FFFF);
+  xEvent.xclient.data.s[2] = 27695;
+
+  if ( XSendEvent( display, win, 0, 0x0000, &xEvent ) == 0 )
+    return result = 0;
+
+  XFlush( display );
+
+  XSetErrorHandler( errorHandler );
+  return result;
+}
+
+//---------------------------------------------
+int SVTK_SpaceMouse::close(Display *display)
+{
+  initialize( display, (Window)InputFocus );
+  spaceMouseOn = 0;
+  
+  return 1;
+}
+
+//---------------------------------------------
+int SVTK_SpaceMouse::translateEvent( Display* display, XEvent* xEvent, MoveEvent* spaceMouseEvent,
+                   double scale, double rScale )
+{
+  if ( !spaceMouseOn )
+    return 0;
+
+  if ( xEvent->type == ClientMessage ) {
+    if ( xEvent->xclient.message_type == XMotionEvent ) {
+      spaceMouseEvent->type = SpaceMouseMove;
+      spaceMouseEvent->data[ x ] =
+       xEvent->xclient.data.s[2] * scale;
+      spaceMouseEvent->data[ y ] =
+       xEvent->xclient.data.s[3] * scale;
+      spaceMouseEvent->data[ z ] =
+       xEvent->xclient.data.s[4] * scale;
+      spaceMouseEvent->data[ a ] =
+       xEvent->xclient.data.s[5] * rScale;
+      spaceMouseEvent->data[ b ] =
+       xEvent->xclient.data.s[6] * rScale;
+      spaceMouseEvent->data[ c ] =
+       xEvent->xclient.data.s[7] * rScale;
+      spaceMouseEvent->period = xEvent->xclient.data.s[8];
+      return 1;
+    }
+    else if ( xEvent->xclient.message_type == XButtonPressEvent ) {
+      spaceMouseEvent->type = SpaceButtonPress;
+      spaceMouseEvent->button = xEvent->xclient.data.s[2];
+      return 2;
+    }
+    else if ( xEvent->xclient.message_type == XButtonReleaseEvent ) {
+      spaceMouseEvent->type = SpaceButtonRelease;
+      spaceMouseEvent->button = xEvent->xclient.data.s[2];
+      return 3;
+    }
+  }
+  return (!display);
+}
+
diff --git a/src/SVTK/SVTK_SpaceMouse.h b/src/SVTK/SVTK_SpaceMouse.h
new file mode 100644 (file)
index 0000000..57a6f84
--- /dev/null
@@ -0,0 +1,75 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : SVTK_SpaceMouse.h
+//  Author : Alexander SLADKOV
+//  Module : SALOME
+//  $Header$
+
+#ifndef SVTK_SpaceMouse_h
+#define SVTK_SpaceMouse_h
+
+extern "C"
+{
+#include <X11/X.h>
+#include <X11/Xlib.h>
+}
+
+class SVTK_SpaceMouse 
+{
+ public:
+
+  // access to SpaceMouse utility class
+  static SVTK_SpaceMouse* getInstance();
+
+  enum MoveData { x, y, z, a, b, c };
+  enum EventType { SpaceMouseMove = 1, SpaceButtonPress, SpaceButtonRelease };
+
+  typedef struct  {
+    int type;
+    int button;
+    double data[6];
+    int period;
+  } MoveEvent;
+
+  bool isSpaceMouseOn() const { return spaceMouseOn != 0; }
+
+  int initialize     ( Display*, Window );
+  int setWindow      ( Display*, Window );
+  int translateEvent ( Display*, XEvent*, MoveEvent*, double, double );
+  int close          ( Display* );
+
+ private:
+  SVTK_SpaceMouse();
+  static SVTK_SpaceMouse* myInstance;
+
+  Atom XMotionEvent;
+  Atom XButtonPressEvent;
+  Atom XButtonReleaseEvent;
+  Atom XCommandEvent;
+
+  Window win;
+  int spaceMouseOn;
+};
+
+#endif
diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx
new file mode 100644 (file)
index 0000000..966ff23
--- /dev/null
@@ -0,0 +1,546 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  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 
+//
+//
+//
+//  File   : 
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#include "SALOME_Actor.h"
+
+#include "SVTK_View.h"
+#include "SVTK_Renderer.h"
+#include "SVTK_MainWindow.h"
+#include "SVTK_RenderWindowInteractor.h"
+#include "SALOME_ListIteratorOfListIO.hxx"
+
+#include "VTKViewer_Algorithm.h"
+#include "SVTK_Functor.h"
+
+#include <vtkActorCollection.h>
+#include <vtkRenderer.h>
+
+
+//----------------------------------------------------------------------------
+SVTK_SignalHandler
+::SVTK_SignalHandler(SVTK_MainWindow* theMainWindow):
+  QObject(theMainWindow),
+  myMainWindow(theMainWindow)
+{
+  SVTK_RenderWindowInteractor* anInteractor = theMainWindow->GetInteractor();
+
+  connect(anInteractor,SIGNAL(KeyPressed(QKeyEvent*)),
+         this,SIGNAL(KeyPressed(QKeyEvent*)) );
+  connect(anInteractor,SIGNAL(KeyReleased(QKeyEvent*)),
+         this,SIGNAL(KeyReleased(QKeyEvent*)));
+  connect(anInteractor,SIGNAL(MouseButtonPressed(QMouseEvent*)),
+         this,SIGNAL(MouseButtonPressed(QMouseEvent*)));
+  connect(anInteractor,SIGNAL(MouseButtonReleased(QMouseEvent*)),
+         this,SIGNAL(MouseButtonReleased(QMouseEvent*)));
+  connect(anInteractor,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
+         this,SIGNAL(MouseDoubleClicked(QMouseEvent*)));
+  connect(anInteractor,SIGNAL(MouseMove(QMouseEvent*)),
+         this,SIGNAL(MouseMove(QMouseEvent*)));
+  connect(anInteractor,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
+         this,SIGNAL(contextMenuRequested(QContextMenuEvent*)));
+  connect(anInteractor,SIGNAL(selectionChanged()),
+         this,SIGNAL(selectionChanged()));
+}
+
+SVTK_SignalHandler
+::~SVTK_SignalHandler()
+{
+}
+
+SVTK_MainWindow*
+SVTK_SignalHandler
+::GetMainWindow()
+{
+  return myMainWindow;
+}
+
+
+//----------------------------------------------------------------
+void
+SVTK_SignalHandler
+::Repaint(bool theUpdateTrihedron)
+{
+  myMainWindow->Repaint(theUpdateTrihedron);
+}
+
+//----------------------------------------------------------------------------
+SVTK_Renderer* 
+SVTK_SignalHandler
+::GetRenderer()
+{
+  return myMainWindow->GetRenderer();
+}
+
+vtkRenderer* 
+SVTK_SignalHandler
+::getRenderer()
+{
+  return myMainWindow->getRenderer();
+}
+
+//----------------------------------------------------------------
+namespace SVTK
+{
+  struct THighlightAction
+  {
+    bool myIsHighlight;
+    THighlightAction( bool theIsHighlight ):
+      myIsHighlight( theIsHighlight )
+    {}
+    
+    void
+    operator()( SALOME_Actor* theActor) 
+    {
+      if(theActor->GetMapper() && theActor->hasIO()){
+       theActor->Highlight( myIsHighlight );
+      }
+    }
+  };
+}
+
+void
+SVTK_SignalHandler
+::onSelectionChanged()
+{
+  vtkActorCollection* anActors = myMainWindow->getRenderer()->GetActors();
+
+  using namespace SVTK;
+  ForEach<SALOME_Actor>(anActors,
+                       THighlightAction( false ));
+  SVTK_Selector* aSelector = myMainWindow->GetSelector();
+  const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
+  SALOME_ListIteratorOfListIO anIter(aListIO);
+  for(; anIter.More(); anIter.Next()){
+    ForEachIf<SALOME_Actor>(anActors,
+                           TIsSameIObject<SALOME_Actor>(anIter.Value()),
+                           THighlightAction(true));
+  }
+
+  myMainWindow->Repaint(false);
+}
+
+
+//----------------------------------------------------------------------------
+SVTK_View
+::SVTK_View(SVTK_MainWindow* theMainWindow) :
+  SVTK_SignalHandler(theMainWindow)
+{
+}
+
+//----------------------------------------------------------------------------
+SVTK_View
+::~SVTK_View()
+{
+}
+
+//----------------------------------------------------------------
+void 
+SVTK_View
+::unHighlightAll() 
+{
+  using namespace SVTK;
+  ForEach<SALOME_Actor>(getRenderer()->GetActors(),
+                       THighlightAction( false ));
+  Repaint();
+}
+
+//----------------------------------------------------------------
+void
+SVTK_View
+::highlight( const Handle(SALOME_InteractiveObject)& theIO, 
+            bool theIsHighlight, 
+            bool theIsUpdate ) 
+{
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>( theIO ),
+                         THighlightAction(theIsHighlight));
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::SetSelectionProp(const double& theRed, 
+                  const double& theGreen, 
+                  const double& theBlue, 
+                  const int& theWidth) 
+{
+  GetRenderer()->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::SetPreselectionProp(const double& theRed, 
+                     const double& theGreen, 
+                     const double& theBlue, 
+                     const int& theWidth) 
+{
+  GetRenderer()->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::SetSelectionTolerance(const double& theTolNodes, 
+                       const double& theTolCell)
+{
+  GetRenderer()->SetSelectionTolerance(theTolNodes,theTolCell);
+}
+
+//----------------------------------------------------------------------------
+bool
+SVTK_View
+::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
+{
+  using namespace SVTK;
+  SALOME_Actor* anActor = 
+    Find<SALOME_Actor>(getRenderer()->GetActors(),
+                      TIsSameIObject<SALOME_Actor>(theIObject));
+  return anActor != NULL;
+}
+
+//----------------------------------------------------------------------------
+bool
+SVTK_View
+::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
+{
+  using namespace SVTK;
+  SALOME_Actor* anActor = 
+    Find<SALOME_Actor>(getRenderer()->GetActors(),
+                      TIsSameIObject<SALOME_Actor>(theIObject));
+  return anActor != NULL && anActor->GetVisibility();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::rename(const Handle(SALOME_InteractiveObject)& theIObject, 
+        const QString& theName)
+{
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIObject),
+                         TSetFunction<SALOME_Actor,const char*,QString>
+                         (&SALOME_Actor::setName,theName.latin1()));
+}
+
+//----------------------------------------------------------------------------
+int
+SVTK_View
+::GetDisplayMode() 
+{
+  return myDisplayMode; 
+}
+
+void
+SVTK_View
+::SetDisplayMode(int theMode)
+{
+  if(theMode == 0) 
+    ChangeRepresentationToWireframe();
+  else 
+    ChangeRepresentationToSurface();
+  myDisplayMode = theMode;
+}
+
+void
+SVTK_View
+::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, 
+                int theMode)
+{
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIObject),
+                         TSetFunction<SALOME_Actor,int>
+                         (&SALOME_Actor::setDisplayMode,theMode));
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::ChangeRepresentationToWireframe()
+{
+  ChangeRepresentationToWireframe(getRenderer()->GetActors());
+}
+
+void
+SVTK_View
+::ChangeRepresentationToSurface()
+{
+  ChangeRepresentationToSurface(getRenderer()->GetActors());
+}
+
+
+void
+SVTK_View
+::ChangeRepresentationToWireframe(vtkActorCollection* theCollection)
+{
+  using namespace SVTK;
+  ForEach<SALOME_Actor>(theCollection,
+                       TSetFunction<SALOME_Actor,int>
+                       (&SALOME_Actor::setDisplayMode,0));
+  Repaint();
+}
+
+void
+SVTK_View
+::ChangeRepresentationToSurface(vtkActorCollection* theCollection)
+{
+  using namespace SVTK;
+  ForEach<SALOME_Actor>(theCollection,
+                       TSetFunction<SALOME_Actor,int>
+                       (&SALOME_Actor::setDisplayMode,1));
+  Repaint();
+}
+
+//----------------------------------------------------------------------------
+namespace SVTK
+{
+  struct TErase
+  {
+    VTK::TSetFunction<vtkActor,int> mySetFunction;
+    TErase():
+      mySetFunction(&vtkActor::SetVisibility,false)
+    {}
+    void
+    operator()(SALOME_Actor* theActor)
+    {
+      theActor->SetVisibility(false);
+      // Erase dependent actors
+      vtkActorCollection* aCollection = vtkActorCollection::New(); 
+      theActor->GetChildActors(aCollection);
+      VTK::ForEach<vtkActor>(aCollection,mySetFunction);
+      aCollection->Delete();
+    }
+  };
+}
+
+void
+SVTK_View
+::EraseAll()
+{   
+  using namespace SVTK;
+  ForEach<SALOME_Actor>(getRenderer()->GetActors(),
+                       TErase());
+  Repaint();
+}
+
+void
+SVTK_View
+::DisplayAll()
+{ 
+  using namespace SVTK;
+  ForEach<SALOME_Actor>(getRenderer()->GetActors(),
+                       TSetVisibility<SALOME_Actor>(true));
+  Repaint();
+}
+
+
+void
+SVTK_View
+::Erase(SALOME_Actor* theActor, 
+       bool theIsUpdate)
+{
+  SVTK::TErase()(theActor);
+
+  if(theIsUpdate)
+    Repaint();
+}
+
+
+void
+SVTK_View
+::Erase(const Handle(SALOME_InteractiveObject)& theIObject, 
+       bool theIsUpdate)
+{
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIObject),
+                         TErase());
+  if(theIsUpdate)
+    Repaint();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::Display(SALOME_Actor* theActor, 
+         bool theIsUpdate)
+{
+  GetRenderer()->AddActor(theActor);
+  theActor->SetVisibility(true);
+
+  if(theIsUpdate)
+    Repaint();
+}
+
+void
+SVTK_View
+::Display(const Handle(SALOME_InteractiveObject)& theIObject, 
+         bool theIsUpdate)
+{
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIObject),
+                         TSetVisibility<SALOME_Actor>(true));
+
+  if(theIsUpdate)
+    Repaint();
+}
+
+void
+SVTK_View
+::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
+{
+  EraseAll();
+  Display(theIObject);
+}
+
+
+//----------------------------------------------------------------------------
+namespace SVTK
+{
+  struct TRemoveAction
+  {
+    SVTK_Renderer* myRenderer;
+    TRemoveAction(SVTK_Renderer* theRenderer): 
+      myRenderer(theRenderer)
+    {}
+    void
+    operator()(SALOME_Actor* theActor)
+    {
+      myRenderer->RemoveActor(theActor);
+    }
+  };
+}
+
+void
+SVTK_View
+::Remove(const Handle(SALOME_InteractiveObject)& theIObject, 
+        bool theIsUpdate)
+{
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIObject),
+                         TRemoveAction(GetRenderer()));
+  if(theIsUpdate)
+    Repaint();
+}
+
+void
+SVTK_View
+::Remove(SALOME_Actor* theActor, 
+        bool theIsUpdate)
+{
+  GetRenderer()->RemoveActor(theActor);
+  if(theIsUpdate)
+    Repaint();
+}
+
+void
+SVTK_View
+::RemoveAll(bool theIsUpdate)
+{
+  vtkRenderer* aRenderer = getRenderer();
+  if(vtkActorCollection* anActors = aRenderer->GetActors()){
+    anActors->InitTraversal();
+    while(vtkActor *anAct = anActors->GetNextActor()){
+      if(SALOME_Actor* aSAct = SALOME_Actor::SafeDownCast(anAct)){
+        if(aSAct->hasIO() && aSAct->getIO()->hasEntry())
+          aRenderer->RemoveActor( anAct );
+      }
+    }
+
+    if(theIsUpdate)
+      Repaint();
+  }
+}
+
+//----------------------------------------------------------------------------
+float
+SVTK_View
+::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) 
+{
+  using namespace SVTK;
+  SALOME_Actor* anActor = 
+    Find<SALOME_Actor>(getRenderer()->GetActors(),
+                      TIsSameIObject<SALOME_Actor>(theIObject));
+  if(anActor)
+    return 1.0 - anActor->GetOpacity();
+  return -1.0;
+}
+
+
+void
+SVTK_View
+::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, 
+                 float theTrans)
+{
+  float anOpacity = 1.0 - theTrans;
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIObject),
+                         TSetFunction<SALOME_Actor,float>
+                         (&SALOME_Actor::SetOpacity,anOpacity));
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_View
+::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,
+          const QColor& theColor) 
+{
+  float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.};
+
+  using namespace SVTK;
+  ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
+                         TIsSameIObject<SALOME_Actor>(theIObject),
+                         TSetFunction<SALOME_Actor,const float*>
+                         (&SALOME_Actor::SetColor,aColor));
+}
+
+
+QColor
+SVTK_View
+::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) 
+{
+  using namespace SVTK;
+  SALOME_Actor* anActor = 
+    Find<SALOME_Actor>(getRenderer()->GetActors(),
+                      TIsSameIObject<SALOME_Actor>(theIObject));
+  if(anActor){
+    float r,g,b;
+    anActor->GetColor(r,g,b);
+    return QColor(int(r*255),int(g*255),int(b*255));
+  }
+
+  return QColor(0,0,0);
+}
+
diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h
new file mode 100644 (file)
index 0000000..2512c34
--- /dev/null
@@ -0,0 +1,248 @@
+#ifndef SVTK_VIEW_H
+#define SVTK_VIEW_H
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+#include "SVTK.h"
+#include "SALOME_InteractiveObject.hxx"
+
+#include <qobject.h>
+
+class vtkActorCollection;
+class vtkRenderer;
+
+class SVTK_MainWindow;
+class SVTK_Renderer;
+
+class SALOME_Actor;
+
+//----------------------------------------------------------------------------
+//! Main purpose of the class is to provide a way to customize #SVTK_MainWindow.
+/*!
+  This class is initialized by #SVTK_MainWindow and just pass Qt signals from 
+  corresponding #SVTK_RenderWindowInteractor of the #SVTK_MainWindow.
+  Its main purpose is to provide a simple and flexible way to customize the #SVTK_MainWindow.
+  So, in your own viewer it is possible to derive new #SVTK_MainWindow and 
+  use existing functionality without any modifications.
+ */
+class SVTK_EXPORT SVTK_SignalHandler : public QObject
+{
+  Q_OBJECT;
+
+public:
+  SVTK_SignalHandler(SVTK_MainWindow* theMainWindow);
+
+  virtual
+  ~SVTK_SignalHandler();
+
+  //! Get reference to its #SVTK_MainWindow
+  SVTK_MainWindow*
+  GetMainWindow();
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_MainWindow::Repaint (just for flexibility)
+  void
+  Repaint(bool theUpdateTrihedron = true);
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_MainWindow::GetRenderer (just for flexibility)
+  SVTK_Renderer* 
+  GetRenderer();
+
+  //! Redirect the request to #SVTK_MainWindow::getRenderer (just for flexibility)
+  vtkRenderer* 
+  getRenderer();
+
+  //----------------------------------------------------------------------------
+ public slots:
+  void onSelectionChanged();
+
+ public:
+ signals:
+  void MouseMove( QMouseEvent* );
+  void MouseButtonPressed( QMouseEvent* );
+  void MouseButtonReleased( QMouseEvent* );
+  void MouseDoubleClicked( QMouseEvent* );
+  void ButtonPressed(const QMouseEvent *event);
+  void ButtonReleased(const QMouseEvent *event);
+  void WheelMoved( QWheelEvent* );
+  void KeyPressed( QKeyEvent* );
+  void KeyReleased( QKeyEvent* );
+  void contextMenuRequested( QContextMenuEvent *e );
+  void selectionChanged();
+
+ protected:
+  SVTK_MainWindow* myMainWindow;
+};
+
+
+//----------------------------------------------------------------------------
+//! This class is introduced just for compatibility with old code.
+/*!
+  This class contains frequantly used functionality in old code.
+  Now, you are supposed to extend existing functionality through
+  writing corresponding functors (see SVTK_Functor.h for example).
+ */
+class SVTK_EXPORT SVTK_View : public SVTK_SignalHandler
+{
+  Q_OBJECT;
+
+public:
+  SVTK_View(SVTK_MainWindow* theMainWindow);
+
+  virtual
+  ~SVTK_View();
+  
+  /*  interactive object management */
+  //! To highlight a VTK presentation with the same #SALOME_InteractiveObject
+  void
+  highlight(const Handle(SALOME_InteractiveObject)& IObject, 
+           bool highlight, 
+           bool immediatly = true);
+
+  //! To unhighlight all VTK presentations
+  void
+  unHighlightAll();
+
+  /* Selection Management */
+  Handle(SALOME_InteractiveObject) 
+  FindIObject(const char* Entry);
+
+  //! Check, if the viewer contains a presentatin with defined #SALOME_InteractiveObject
+  bool
+  isInViewer(const Handle(SALOME_InteractiveObject)& IObject);
+
+  //! Check, if a presentatin with defined #SALOME_InteractiveObject is visible
+  bool
+  isVisible(const Handle(SALOME_InteractiveObject)& IObject);
+
+  void
+  rename(const Handle(SALOME_InteractiveObject)& IObject, 
+        const QString& newName);
+  
+  //----------------------------------------------------------------------------
+  // Displaymode management
+  //! Get current display mode (obsolete)
+  int 
+  GetDisplayMode();
+
+  //! Set current display mode
+  void
+  SetDisplayMode(int);
+
+  //! Switch representation wireframe/shading
+  void
+  SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, 
+                int theMode);
+
+  //! Change all actors to wireframe
+  void 
+  ChangeRepresentationToWireframe();
+
+  //! Change all actors to surface
+  void
+  ChangeRepresentationToSurface();
+
+  //! Change to wireframe a list of vtkactor
+  void
+  ChangeRepresentationToWireframe(vtkActorCollection* theListofActors);
+
+  //! Change to surface a list of vtkactor
+  void
+  ChangeRepresentationToSurface(vtkActorCollection* theListofActors);
+
+  //! Change transparency
+  void
+  SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject,
+                 float trans);
+
+  //! Get current transparency
+  float 
+  GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject);
+
+  //! Change color
+  void
+  SetColor(const Handle(SALOME_InteractiveObject)& theIObject,
+          const QColor& theColor);
+
+  //! Get current color
+  QColor
+  GetColor(const Handle(SALOME_InteractiveObject)& theIObject);
+
+  //----------------------------------------------------------------------------
+  // Erase Display functions
+  //! To erase all existing VTK presentations
+  void
+  EraseAll();
+
+  //! To display all existing VTK presentations
+  void
+  DisplayAll();
+
+  //! To remove from the view all existing VTK presentations
+  void
+  RemoveAll( const bool immediatly );
+
+  //! To erase VTK presentation with defined #SALOME_InteractiveObject
+  void
+  Erase(const Handle(SALOME_InteractiveObject)& IObject, 
+       bool immediatly = true);
+  void
+  Remove(const Handle(SALOME_InteractiveObject)& IObject, 
+        bool immediatly = true);
+
+  //! To display VTK presentation with defined #SALOME_InteractiveObject
+  void
+  Display(const Handle(SALOME_InteractiveObject)& IObject, 
+         bool immediatly = true);
+
+  //! To display VTK presentation with defined #SALOME_InteractiveObject and erase all anothers
+  void
+  DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject);
+
+  //! To display the VTK presentation
+  void
+  Display(SALOME_Actor* SActor, 
+         bool immediatly = true);
+
+  //! To erase the VTK presentation
+  void
+  Erase(SALOME_Actor* SActor, 
+       bool immediatly = true);
+
+  //! To remove the VTK presentation
+  void
+  Remove(SALOME_Actor* SActor, 
+        bool updateViewer = true);
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
+  void
+  SetSelectionProp(const double& theRed = 1, 
+                  const double& theGreen = 1,
+                  const double& theBlue = 0, 
+                  const int& theWidth = 5);
+
+  //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
+  void
+  SetPreselectionProp(const double& theRed = 0, 
+                     const double& theGreen = 1,
+                     const double& theBlue = 1, 
+                     const int& theWidth = 5);
+
+  //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
+  void
+  SetSelectionTolerance(const double& theTolNodes = 0.025, 
+                       const double& theTolCell = 0.001);
+
+ protected:  
+  int myDisplayMode;
+};
+
+#ifdef WIN32
+#pragma warning( default:4251 )
+#endif
+
+#endif
index ae3bf47f83c71bfed985c2edbf4aeb98b94a570e..b200ccc5bd5df9ade5e993fd9cc9a3409f99c892 100644 (file)
 
 class SUIT_Desktop;
 
+//! Extend SUIT_ViewManager to deal with SVTK_Viewer
 class SVTK_EXPORT SVTK_ViewManager : public SUIT_ViewManager
 {
   Q_OBJECT
 
 public:
+  //! Construct the view manager
   SVTK_ViewManager( SUIT_Study* study, SUIT_Desktop* );
+
+  //! Destroy the view manager
   virtual ~SVTK_ViewManager();
 
 protected:
index a8a11fbd2e8115a911c6832651112b6733018169..08c2169d53e32a80e1534ca5726943cdbc1fc8f1 100644 (file)
 #include "SVTK_Selection.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
+#include "SVTK_View.h"
+#include "SVTK_MainWindow.h"
 #include "SVTK_Prs.h"
 
 #include "VTKViewer_ViewModel.h"
 
-#include "SVTK_RenderWindowInteractor.h"
-#include "SVTK_RenderWindow.h"
-
-//#include <ToolsGUI.h>
-
 #include <SALOME_Actor.h>
 #include <SALOME_InteractiveObject.hxx>
 
-// Temporarily commented to avoid awful dependecy on SALOMEDS
-// TODO: better mechanism of storing display/erse status in a study
-// should be provided...
-//#include "Utils_ORB_INIT.hxx"
-//#include "Utils_SINGLETON.hxx"
-//#include "SALOME_ModuleCatalog_impl.hxx"
-//#include "SALOME_NamingService.hxx"
-
-//#include "SALOMEDSClient.hxx"
-//#include "SALOMEDS_StudyManager.hxx"
-
 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from 
 // SALOMEDS::StudyManager - no linkage with SalomeApp. 
@@ -76,7 +62,7 @@
 //==========================================================
 SVTK_Viewer::SVTK_Viewer()
 {
-  myTrihedronSize = 100;
+  myTrihedronSize = 105;
 }
 
 //==========================================================
@@ -84,24 +70,44 @@ SVTK_Viewer::~SVTK_Viewer()
 {
 }
 
-QColor SVTK_Viewer::backgroundColor() const
+QColor
+SVTK_Viewer
+::backgroundColor() const
 {
   return myBgColor;
 }
 
-void SVTK_Viewer::setBackgroundColor( const QColor& c )
+void
+SVTK_Viewer
+::setBackgroundColor( const QColor& theColor )
 {
-  if ( c.isValid() )
-    myBgColor = c;
+  if ( !theColor.isValid() )
+    return;
+
+  QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
+  for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
+    if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
+      if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
+       aView->getMainWindow()->SetBackgroundColor(theColor);
+      }
+    }
+  }
+
+  myBgColor = theColor;
 }
 
 //==========================================================
-SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
+SUIT_ViewWindow* 
+SVTK_Viewer::
+createView( SUIT_Desktop* theDesktop )
 {
-  SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this );
-  vw->setBackgroundColor( backgroundColor() );
-  vw->SetTrihedronSize( trihedronSize() );
-  return vw;
+  SVTK_ViewWindow* aViewWindow = new SVTK_ViewWindow(theDesktop);
+  aViewWindow->Initialize(this);
+    
+  aViewWindow->setBackgroundColor( backgroundColor() );
+  aViewWindow->SetTrihedronSize( trihedronSize() );
+
+  return aViewWindow;
 }
 
 int SVTK_Viewer::trihedronSize() const
@@ -148,75 +154,39 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
 }
 
 //==========================================================
-void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup )
+void
+SVTK_Viewer
+::contextMenuPopup( QPopupMenu* thePopup )
 {
   thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
   thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
 
   thePopup->insertSeparator();
 
-  SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
-  if ( aView && !aView->getToolBar()->isVisible() )
-    thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
-}
-
-//==========================================================
-void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
-  if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
-    if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
-      switch(event->button()) {
-      case LeftButton:
-       aRWI->LeftButtonPressed(event) ;
-       break ;
-      case MidButton:
-       aRWI->MiddleButtonPressed(event) ;
-       break ;
-      case RightButton:
-       aRWI->RightButtonPressed(event) ;
-       break;
-      default:
-       break ;
-      }
+  if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
+    if ( !aView->getView()->GetMainWindow()->getToolBar()->isVisible() ){
+      thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
     }
   }
 }
 
+//==========================================================
+void 
+SVTK_Viewer
+::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
+{}
+
 //==========================================================
 void 
 SVTK_Viewer
 ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
-  if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
-    if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
-      aRWI->MouseMove( event );
-    }
-  }
-}
+{}
 
 //==========================================================
 void 
 SVTK_Viewer
 ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
-  if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
-    if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
-      switch(event->button()) {
-      case LeftButton:
-       aRWI->LeftButtonReleased(event) ;
-       break ;
-      case MidButton:
-       aRWI->MiddleButtonReleased(event) ;
-       break ;
-      case RightButton:
-       aRWI->RightButtonReleased(event) ;
-       break;
-      default:
-       break ;
-      }
-    }
-  }
-}
+{}
 
 //==========================================================
 void 
@@ -236,21 +206,22 @@ SVTK_Viewer
   //!! To be done for view windows
 }
 
-void SVTK_Viewer::onDumpView()
+void
+SVTK_Viewer
+::onDumpView()
 {
-  SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
-  if ( aView )
+  if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
     aView->onDumpView();
 }
 
 //==========================================================
-void SVTK_Viewer::onChangeBgColor()
+void
+SVTK_Viewer
+::onChangeBgColor()
 {
-  SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(myViewManager->getActiveView());
-  if ( aView ) {
-    QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView );
-    if ( aColor.isValid() )
-      aView->setBackgroundColor( aColor );
+  if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){
+    QColor aColor = QColorDialog::getColor( backgroundColor(), aView);
+    setBackgroundColor(aColor);
   }
 }
 
@@ -260,10 +231,11 @@ SVTK_Viewer
 ::onShowToolbar() 
 {
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
-  for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-       aView->getToolBar()->show();    
+  for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
+    if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))){
+      aView->getView()->GetMainWindow()->getToolBar()->show();
+    }
+  }
 }
 
 //==========================================================
@@ -295,14 +267,12 @@ SVTK_Viewer
          // just display the object
          QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
          for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
-           if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
-             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
-               if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()){
-                 aRWI->Display(anAct,false);
-                 if(anAct->IsSetCamera()){
-                   vtkRenderer* aRenderer =  aView->getRenderer();
-                   anAct->SetCamera( aRenderer->GetActiveCamera() );
-                 }
+           if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
+             if(SVTK_View* aView = aViewWindow->getView()){
+               aView->Display(anAct,false);
+               if(anAct->IsSetCamera()){
+                 vtkRenderer* aRenderer = aView->getRenderer();
+                 anAct->SetCamera( aRenderer->GetActiveCamera() );
                }
              }
            }
@@ -342,13 +312,12 @@ SVTK_Viewer
          // just display the object
          QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
          for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
-           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-               if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
-                 if ( forced )
-                   aRWI->Remove(anAct,false);
-                 else
-                   aRWI->Erase(anAct,forced);
+           if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+             if(SVTK_View* aView = aViewWindow->getView())
+               if ( forced )
+                 aView->Remove(anAct,false);
+               else
+                 aView->Erase(anAct,forced);
          }
        }
     }
@@ -366,11 +335,8 @@ SVTK_Viewer
   //_PTR(Study) aStudy(getStudyDS());
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
-
-       aView->unHighlightAll();
-
+    if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+      if(SVTK_View* aView = aViewWindow->getView()){
        vtkRenderer* aRenderer =  aView->getRenderer();
        vtkActorCollection* anActorCollection = aRenderer->GetActors();
        anActorCollection->InitTraversal();
@@ -399,7 +365,6 @@ SVTK_Viewer
          }
        }
       }
-    }
   }
   Repaint();
 }
@@ -411,16 +376,19 @@ SVTK_Viewer
 {
   SVTK_Prs* prs = new SVTK_Prs();
   if ( entry ) {
-    vtkRenderer* rnr =  ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer();
-    vtkActorCollection* theActors = rnr->GetActors();
-    theActors->InitTraversal();
-    vtkActor* ac;
-    while( ( ac = theActors->GetNextActor() ) ) {
-      SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
-      if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
-       prs->AddObject( ac );
+    if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
+      if(SVTK_View* aView = aViewWindow->getView()){
+       vtkRenderer* aRenderer =  aView->getRenderer();
+       vtkActorCollection* theActors = aRenderer->GetActors();
+       theActors->InitTraversal();
+       vtkActor* ac;
+       while( ( ac = theActors->GetNextActor() ) ) {
+         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
+         if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
+           prs->AddObject( ac );
+         }
+       }
       }
-    }
   }
   return prs;
 }
@@ -447,11 +415,11 @@ SVTK_Viewer
 {
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-       if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
-         if(!aRWI->isVisible( io ))
-           return false;
+    if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+      if(SVTK_View* aView = aViewWindow->getView())
+       if(!aView->isVisible( io ))
+         return false;
+
   return true;
 }
 
@@ -463,16 +431,7 @@ SVTK_Viewer
 //  if (theUpdateTrihedron) onAdjustTrihedron();
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-       if(SVTK_RenderWindow* aRW = aView->getRenderWindow())
-         aRW->update();
+    if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+      if(SVTK_View* aView = aViewWindow->getView())
+       aView->Repaint();
 }
-
-void 
-SVTK_Viewer
-::onSelectionChanged()
-{
-  emit selectionChanged();
-}
-
index 7e70759fa240e0a384fe8c3b6ed2d78f9243a34a..5875d465e57aecb54e59b34d820ee5c37d246beb 100644 (file)
 
 #include "SVTK.h"
 #include "SUIT_ViewModel.h"
+#include "SVTK_ViewModelBase.h"
 
 #include "SALOME_Prs.h"
 #include "SALOME_InteractiveObject.hxx"
 
 #include <qcolor.h>
 
-class SVTK_EXPORT SVTK_Viewer : public SUIT_ViewModel, public SALOME_View 
+class SVTK_ViewWindow;
+
+//! Extends two interfaces #SVTK_ViewModelBase and #SALOME_View 
+class SVTK_EXPORT SVTK_Viewer : public SVTK_ViewModelBase, public SALOME_View 
 {
   Q_OBJECT;
 
 public:
+  typedef SVTK_ViewWindow TViewWindow;
+  
+  //! Define string representation of the viewer type
   static QString Type() { return "VTKViewer"; }
 
   SVTK_Viewer();
   virtual ~SVTK_Viewer();
 
+  //! See #SUIT_ViewModel::createView
   virtual SUIT_ViewWindow* createView(SUIT_Desktop*);
 
-  virtual void             setViewManager(SUIT_ViewManager* theViewManager);
-  virtual void             contextMenuPopup( QPopupMenu* );
-  virtual QString          getType() const { return Type(); }
+  //! See #SUIT_ViewModel::createView
+  virtual void setViewManager(SUIT_ViewManager* theViewManager);
+
+  //! See #SUIT_ViewModel::contextMenuPopup
+  virtual void contextMenuPopup( QPopupMenu* );
 
+  //! See #SUIT_ViewModel::getType
+  virtual QString getType() const { return Type(); }
+
+  //! Get background color of the viewer
   QColor backgroundColor() const;
-  void   setBackgroundColor( const QColor& );
 
-  int    trihedronSize() const;
-  void   setTrihedronSize( const int );
+  //! Set background color to the viewer
+  void setBackgroundColor( const QColor& );
+
+  //! Get size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize)
+  int trihedronSize() const;
+
+  //! Set size of trihedron of the viewer (see #SVTK_Renderer::SetTrihedronSize)
+  void setTrihedronSize( const int );
 
 public:
   void enableSelection(bool isEnabled);
@@ -59,24 +78,30 @@ public:
   int  getSelectionCount() const;
 
   /* Reimplemented from SALOME_View */
-  void                           Display( const SALOME_VTKPrs* );
-  void                           Erase( const SALOME_VTKPrs*, const bool = false );
-  void                           EraseAll( const bool = false );
-  SALOME_Prs*                    CreatePrs( const char* entry = 0 );
-  virtual void                   BeforeDisplay( SALOME_Displayer* d );
-  virtual void                   AfterDisplay ( SALOME_Displayer* d );
-  virtual bool                   isVisible( const Handle(SALOME_InteractiveObject)& );
-  virtual void                   Repaint();
-
-  //implemented in SOCC, but were not found in VTKVIEwer_ViewFrame, so not implemented here..
-  //?virtual void                LocalSelection( const SALOME_OCCPrs*, const int );
-  //?virtual void                GlobalSelection( const bool = false ) const;
-
-public slots:
-  void onSelectionChanged();
-
- signals:
-  void selectionChanged();
+
+  //! See #SALOME_View::Display( const SALOME_Prs* )
+  void Display( const SALOME_VTKPrs* ); 
+
+  //! See #SALOME_View::Erase( const SALOME_VTKPrs*, const bool = false )
+  void Erase( const SALOME_VTKPrs*, const bool = false );
+
+  //! See #SALOME_View::EraseAll( const bool = false )
+  void EraseAll( const bool = false );
+
+  //! See #SALOME_View::CreatePrs( const char* entry = 0 )
+  SALOME_Prs* CreatePrs( const char* entry = 0 );
+
+  //! See #SALOME_View::BeforeDisplay( SALOME_Displayer* d )
+  virtual void BeforeDisplay( SALOME_Displayer* d );
+
+  //! See #SALOME_View::AfterDisplay( SALOME_Displayer* d )
+  virtual void AfterDisplay( SALOME_Displayer* d );
+
+  //! See #SALOME_View::isVisible( const Handle(SALOME_InteractiveObject)& )
+  virtual bool isVisible( const Handle(SALOME_InteractiveObject)& );
+
+  //! See #SALOME_View::Repaint()
+  virtual void Repaint();
 
 protected slots:
   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
diff --git a/src/SVTK/SVTK_ViewModelBase.h b/src/SVTK/SVTK_ViewModelBase.h
new file mode 100644 (file)
index 0000000..d588272
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef SVTK_SELECTIONCHANGED_H
+#define SVTK_SELECTIONCHANGED_H
+
+#include <qobject.h>
+
+#include "SVTK.h"
+#include "SUIT_ViewModel.h"
+
+
+//! To define minimal interface for #SVTK_ViewWindow initialization
+class SVTK_EXPORT SVTK_ViewModelBase: public SUIT_ViewModel
+{
+  Q_OBJECT;
+
+public slots:
+  //! To invoke Qt #selectionChanged signal
+  void onSelectionChanged()
+  {
+    emit selectionChanged();
+  }
+
+ signals:
+  //! To declare signal on selection changed
+  void selectionChanged();
+};
+
+#endif
index c4d09f5f879ba0c23e008103dee40579fae812b0..b95a23d20a35b7a479fa6438cfd6e9a0b62fb034 100755 (executable)
@@ -26,6 +26,8 @@
 #include <vtkRenderWindow.h>
 #include <vtkRenderer.h>
 #include <vtkCamera.h>
+#include <vtkPointPicker.h>
+#include <vtkCellPicker.h>
 
 #include "QtxAction.h"
 
 
 #include "SUIT_Tools.h"
 #include "SUIT_ResourceMgr.h"
+#include "SUIT_Accel.h"
 
-#include "VTKViewer_Transform.h"
 #include "VTKViewer_Utilities.h"
 
-#include "SVTK_Trihedron.h"
-#include "SVTK_CubeAxesActor2D.h"
+#include "SVTK_View.h"
+#include "SVTK_MainWindow.h"
+#include "SVTK_Selector.h"
+
+#include "SVTK_Event.h"
+#include "SVTK_Renderer.h"
 #include "SVTK_ViewWindow.h"
-#include "SVTK_ViewModel.h"
-#include "SVTK_RenderWindow.h"
-#include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_ViewModelBase.h"
 #include "SVTK_InteractorStyle.h"
+#include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_GenericRenderWindowInteractor.h"
 
 #include "SALOME_ListIteratorOfListIO.hxx"
 
-#include "SVTK_SelectorDef.h"
-
 #include "VTKViewer_Algorithm.h"
 #include "SVTK_Functor.h"
 
 //----------------------------------------------------------------------------
 SVTK_ViewWindow
-::SVTK_ViewWindow( SUIT_Desktop* theDesktop, 
-                  SVTK_Viewer* theModel)
-  : SUIT_ViewWindow( theDesktop ),
-    myTrihedronSize( 100 )
-{
-  myModel = theModel;
-  mySelector = new SVTK_SelectorDef();
-  connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
-
-  myTransform = VTKViewer_Transform::New();
-  myTrihedron = SVTK_Trihedron::New();
-  myCubeAxes  = SVTK_CubeAxesActor2D::New();
-  myRenderer  = vtkRenderer::New() ;
-
-  myTrihedron->AddToRender( myRenderer );
-  myRenderer->AddProp(myCubeAxes);
-
-  myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" );
-  setCentralWidget(myRenderWindow);
-  myRenderWindow->setFocusPolicy( StrongFocus );
-  myRenderWindow->setFocus();
-
-  myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
-
-  myRenderer->GetActiveCamera()->ParallelProjectionOn();
-  myRenderer->LightFollowCameraOn();
-  myRenderer->TwoSidedLightingOn();
-
-  // Set BackgroundColor
-  QString BgrColorRed   = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
-  QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
-  QString BgrColorBlue  = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
-
-  if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) 
-    myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
-  else
-    myRenderer->SetBackground( 0, 0, 0 );
-  
-  // Create an interactor.
-  myRWInteractor = SVTK_RenderWindowInteractor::New();
-  myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
-  myRWInteractor->setViewWindow( this );
-
-  SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
-  RWS->setGUIWindow( myRenderWindow );
-  RWS->setViewWindow( this );
-
-  myRWInteractor->SetInteractorStyle( RWS ); 
-  myRWInteractor->Initialize();
-
-  //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
-  RWS->FindPokedRenderer( 0, 0 );
-
-  SetSelectionMode(ActorSelection);
-
-  vtkTextProperty* tprop = vtkTextProperty::New();
-  tprop->SetColor(1, 1, 1);
-  tprop->ShadowOn();
-  
-  float bnd[6];
-  bnd[0] = bnd[2] = bnd[4] = 0;
-  bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize();
-  myCubeAxes->SetLabelFormat("%6.4g");
-  myCubeAxes->SetBounds(bnd);
-  myCubeAxes->SetCamera(myRenderer->GetActiveCamera());
-  myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
-  myCubeAxes->SetFontFactor(0.8);
-  myCubeAxes->SetAxisTitleTextProperty(tprop);
-  myCubeAxes->SetAxisLabelTextProperty(tprop);
-  myCubeAxes->SetCornerOffset(0);
-  myCubeAxes->SetScaling(0);
-  myCubeAxes->SetNumberOfLabels(5);
-  myCubeAxes->VisibilityOff();
-  myCubeAxes->SetTransform(myTransform);
-  tprop->Delete();
-  
-  setCentralWidget( myRenderWindow );
-
-  myToolBar = new QToolBar(this);
-  myToolBar->setCloseMode(QDockWindow::Undocked);
-  myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
-
-  createActions();
-  createToolBar();
-
-  connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
-           this,           SLOT(onKeyPressed( QKeyEvent* )) );
-  connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
-           this,           SLOT(onKeyReleased( QKeyEvent* )) );
-  connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
-           this,           SLOT(onMousePressed( QMouseEvent* )) );
-  connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
-           this,           SLOT(onMouseReleased( QMouseEvent* )) );
-  connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
-           this,           SLOT(onMouseDoubleClicked( QMouseEvent* )) );
-  connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
-           this,           SLOT(onMouseMoving( QMouseEvent* )) );
-
-  connect( myRWInteractor, SIGNAL(RenderWindowModified()),
-           myRenderWindow, SLOT(update()) );
-  connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
-           this,           SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
-
-  onResetView();
-}
+::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
+  SUIT_ViewWindow(theDesktop),
+  myMainWindow(NULL),
+  myView(NULL)
+{}
 
-//----------------------------------------------------------------------------
+void
 SVTK_ViewWindow
-::~SVTK_ViewWindow()
+::Initialize(SVTK_ViewModelBase* theModel)
 {
-  myTransform->Delete();
-  // In order to ensure that the interactor unregisters
-  // this RenderWindow, we assign a NULL RenderWindow to 
-  // it before deleting it.
-  myRWInteractor->SetRenderWindow( NULL );
-  myRWInteractor->Delete();
-  
-  //m_RW->Delete() ;
-  myRenderer->RemoveAllProps();
-  //m_Renderer->Delete();
-  myTrihedron->Delete();
-  myCubeAxes->Delete();
+  if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){
+    myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr,this);
+
+    SVTK_RenderWindowInteractor* anIteractor = 
+      new SVTK_RenderWindowInteractor(myMainWindow,"SVTK_RenderWindowInteractor");
+
+    SVTK_Selector* aSelector = SVTK_Selector::New();
+
+    SVTK_GenericRenderWindowInteractor* aDevice = 
+      SVTK_GenericRenderWindowInteractor::New();
+    aDevice->SetRenderWidget(anIteractor);
+    aDevice->SetSelector(aSelector);
+
+    SVTK_Renderer* aRenderer = SVTK_Renderer::New();
+    aRenderer->Initialize(aDevice,aSelector);
+
+    anIteractor->Initialize(aDevice,aRenderer,aSelector);
+
+    aDevice->Delete();
+    aRenderer->Delete();
+    aSelector->Delete();
+
+    myMainWindow->Initialize(anIteractor);
+
+    SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
+    anIteractor->PushInteractorStyle(aStyle);
+    aStyle->Delete();
+
+    setCentralWidget(myMainWindow);
+    
+    myView = new SVTK_View(myMainWindow);
+    Initialize(myView,theModel);
+  }
 }
 
-//----------------------------------------------------------------------------
 void
 SVTK_ViewWindow
-::activateZoom()
+::Initialize(SVTK_View* theView,
+            SVTK_ViewModelBase* theModel)
 {
-  myRWInteractor->GetSInteractorStyle()->startZoom();
+  connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
+          this,SLOT(onKeyPressed(QKeyEvent*)) );
+  connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
+          this,SLOT(onKeyReleased(QKeyEvent*)));
+  connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
+          this,SLOT(onMousePressed(QMouseEvent*)));
+  connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
+          this,SLOT(onMouseReleased(QMouseEvent*)));
+  connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
+          this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
+  connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
+          this,SLOT(onMouseMoving(QMouseEvent*)));
+  connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
+          this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
+  connect(theView,SIGNAL(selectionChanged()),
+         theModel,SLOT(onSelectionChanged()));
 }
 
-//----------------------------------------------------------------------------
-void
 SVTK_ViewWindow
-::activatePanning()
-{
-  myRWInteractor->GetSInteractorStyle()->startPan();
-}
+::~SVTK_ViewWindow()
+{}
+
 
 //----------------------------------------------------------------------------
-void
+SVTK_View* 
 SVTK_ViewWindow
-::activateRotation()
-{
-  myRWInteractor->GetSInteractorStyle()->startRotate();
+::getView() 
+{ 
+  return myView; 
 }
 
-//----------------------------------------------------------------------------
-void
+SVTK_MainWindow* 
 SVTK_ViewWindow
-::activateGlobalPanning()
-{
-  if(myTrihedron->GetVisibleActorCount(myRenderer))
-    myRWInteractor->GetSInteractorStyle()->startGlobalPan();
+::getMainWindow() 
+{ 
+  return myMainWindow; 
 }
 
-//----------------------------------------------------------------------------
-void
+vtkRenderWindow*
 SVTK_ViewWindow
-::activateWindowFit()
+::getRenderWindow()
 {
-  myRWInteractor->GetSInteractorStyle()->startFitArea();
+  return getMainWindow()->getRenderWindow();
 }
 
-//----------------------------------------------------------------------------
-#if defined(WIN32) && !defined(_DEBUG)
-#pragma optimize( "", off )
-#endif
-void
+vtkRenderWindowInteractor*
 SVTK_ViewWindow
-::createActions()
+::getInteractor()
 {
-  if (!myActionsMap.isEmpty()) return;
-  
-  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
-  
-  QtxAction* aAction;
-
-  // Dump view
-  aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
-                           tr( "MNU_DUMP_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
-  myActionsMap[ DumpId ] = aAction;
-
-  // FitAll
-  aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
-                           tr( "MNU_FITALL" ), 0, this);
-  aAction->setStatusTip(tr("DSC_FITALL"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
-  myActionsMap[ FitAllId ] = aAction;
-
-  // FitRect
-  aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
-                           tr( "MNU_FITRECT" ), 0, this);
-  aAction->setStatusTip(tr("DSC_FITRECT"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
-  myActionsMap[ FitRectId ] = aAction;
-
-  // Zoom
-  aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
-                           tr( "MNU_ZOOM_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
-  myActionsMap[ ZoomId ] = aAction;
-
-  // Panning
-  aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
-                           tr( "MNU_PAN_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_PAN_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
-  myActionsMap[ PanId ] = aAction;
-
-  // Global Panning
-  aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
-                           tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
-  myActionsMap[ GlobalPanId ] = aAction;
-
-  // Rotation
-  aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
-                           tr( "MNU_ROTATE_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
-  myActionsMap[ RotationId ] = aAction;
-
-  // Projections
-  aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
-                           tr( "MNU_FRONT_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
-  myActionsMap[ FrontId ] = aAction;
-
-  aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
-                           tr( "MNU_BACK_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_BACK_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
-  myActionsMap[ BackId ] = aAction;
-
-  aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
-                           tr( "MNU_TOP_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_TOP_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
-  myActionsMap[ TopId ] = aAction;
-
-  aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
-                           tr( "MNU_BOTTOM_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
-  myActionsMap[ BottomId ] = aAction;
-
-  aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
-                           tr( "MNU_LEFT_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
-  myActionsMap[ LeftId ] = aAction;
-
-  aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
-                           tr( "MNU_RIGHT_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
-  myActionsMap[ RightId ] = aAction;
-
-  // Reset
-  aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
-                           tr( "MNU_RESET_VIEW" ), 0, this);
-  aAction->setStatusTip(tr("DSC_RESET_VIEW"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
-  myActionsMap[ ResetId ] = aAction;
-
-  // onViewTrihedron: Shows - Hides Trihedron
-  aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
-                           tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
-  aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
-  connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
-  myActionsMap[ ViewTrihedronId ] = aAction;
+  return getMainWindow()->getInteractor();
 }
-#if defined(WIN32) && !defined(_DEBUG)
-#pragma optimize( "", on )
-#endif
 
-//----------------------------------------------------------------------------
-void
+vtkRenderer*
 SVTK_ViewWindow
-::createToolBar()
+::getRenderer()
 {
-  myActionsMap[DumpId]->addTo(myToolBar);
-  myActionsMap[ViewTrihedronId]->addTo(myToolBar);
-
-  SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
-  aScaleBtn->AddAction(myActionsMap[FitAllId]);
-  aScaleBtn->AddAction(myActionsMap[FitRectId]);
-  aScaleBtn->AddAction(myActionsMap[ZoomId]);
-
-  SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
-  aPanningBtn->AddAction(myActionsMap[PanId]);
-  aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
-
-  myActionsMap[RotationId]->addTo(myToolBar);
-
-  SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
-  aViewsBtn->AddAction(myActionsMap[FrontId]);
-  aViewsBtn->AddAction(myActionsMap[BackId]);
-  aViewsBtn->AddAction(myActionsMap[TopId]);
-  aViewsBtn->AddAction(myActionsMap[BottomId]);
-  aViewsBtn->AddAction(myActionsMap[LeftId]);
-  aViewsBtn->AddAction(myActionsMap[RightId]);
+  return myMainWindow->getRenderer();
+}
 
-  myActionsMap[ResetId]->addTo(myToolBar);
+SVTK_Selector* 
+SVTK_ViewWindow
+::GetSelector() 
+{ 
+  return myMainWindow->GetSelector(); 
 }
 
+
 //----------------------------------------------------------------------------
 void
 SVTK_ViewWindow
 ::onFrontView()
 {
-  vtkCamera* camera = myRenderer->GetActiveCamera();
-  camera->SetPosition(1,0,0);
-  camera->SetViewUp(0,0,1);
-  camera->SetFocalPoint(0,0,0);
-  onFitAll();
+  myMainWindow->onFrontView();
 }
 
 //----------------------------------------------------------------------------
@@ -387,11 +191,7 @@ void
 SVTK_ViewWindow
 ::onBackView()
 {
-  vtkCamera* camera = myRenderer->GetActiveCamera();
-  camera->SetPosition(-1,0,0);
-  camera->SetViewUp(0,0,1);
-  camera->SetFocalPoint(0,0,0);
-  onFitAll();
+  myMainWindow->onBackView();
 }
 
 //----------------------------------------------------------------------------
@@ -399,11 +199,7 @@ void
 SVTK_ViewWindow
 ::onTopView()
 {
-  vtkCamera* camera = myRenderer->GetActiveCamera();
-  camera->SetPosition(0,0,1);
-  camera->SetViewUp(0,1,0);
-  camera->SetFocalPoint(0,0,0);
-  onFitAll();
+  myMainWindow->onTopView();
 }
 
 //----------------------------------------------------------------------------
@@ -411,11 +207,7 @@ void
 SVTK_ViewWindow
 ::onBottomView()
 {
-  vtkCamera* camera = myRenderer->GetActiveCamera();
-  camera->SetPosition(0,0,-1);
-  camera->SetViewUp(0,1,0);
-  camera->SetFocalPoint(0,0,0);
-  onFitAll();
+  myMainWindow->onBottomView();
 }
 
 //----------------------------------------------------------------------------
@@ -423,11 +215,7 @@ void
 SVTK_ViewWindow
 ::onLeftView()
 {
-  vtkCamera* camera = myRenderer->GetActiveCamera(); 
-  camera->SetPosition(0,-1,0);
-  camera->SetViewUp(0,0,1);
-  camera->SetFocalPoint(0,0,0);
-  onFitAll();
+  myMainWindow->onLeftView();
 }
 
 //----------------------------------------------------------------------------
@@ -435,11 +223,7 @@ void
 SVTK_ViewWindow
 ::onRightView()
 {
-  vtkCamera* camera = myRenderer->GetActiveCamera();
-  camera->SetPosition(0,1,0);
-  camera->SetViewUp(0,0,1);
-  camera->SetFocalPoint(0,0,0);
-  onFitAll();
+  myMainWindow->onRightView();
 }
 
 //----------------------------------------------------------------------------
@@ -447,27 +231,7 @@ void
 SVTK_ViewWindow
 ::onResetView()
 {
-  int aTrihedronIsVisible = isTrihedronDisplayed();
-  int aCubeAxesIsVisible  = isCubeAxesDisplayed();
-
-  myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
-  myCubeAxes->SetVisibility(0);
-
-  ::ResetCamera(myRenderer,true);  
-  vtkCamera* aCamera = myRenderer->GetActiveCamera();
-  aCamera->SetPosition(1,-1,1);
-  aCamera->SetViewUp(0,0,1);
-  ::ResetCamera(myRenderer,true);  
-
-  if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
-  else myTrihedron->VisibilityOff();
-
-  if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
-  else myCubeAxes->VisibilityOff();
-
-  static float aCoeff = 3.0;
-  aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
-  Repaint();
+  myMainWindow->onResetView();
 }
 
 //----------------------------------------------------------------------------
@@ -475,43 +239,7 @@ void
 SVTK_ViewWindow
 ::onFitAll()
 {
-  int aTrihedronWasVisible = false;
-  int aCubeAxesWasVisible = false;
-  if (myTrihedron) {
-    aTrihedronWasVisible = isTrihedronDisplayed();
-    if (aTrihedronWasVisible)
-      myTrihedron->VisibilityOff();
-  }
-
-  if (myCubeAxes) {
-    aCubeAxesWasVisible = isCubeAxesDisplayed();
-    if (aCubeAxesWasVisible)
-      myCubeAxes->VisibilityOff();
-  }
-
-  if (myTrihedron->GetVisibleActorCount(myRenderer)) {
-    myTrihedron->VisibilityOff();
-    myCubeAxes->VisibilityOff();
-    ::ResetCamera(myRenderer);
-  } else {
-    myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
-    myCubeAxes->SetVisibility(2);
-    ::ResetCamera(myRenderer,true);
-  }
-
-  if (aTrihedronWasVisible)
-    myTrihedron->VisibilityOn();
-  else
-    myTrihedron->VisibilityOff();
-
-  if (aCubeAxesWasVisible)
-    myCubeAxes->VisibilityOn();
-  else
-    myCubeAxes->VisibilityOff();
-
-  ::ResetCameraClippingRange(myRenderer);
-
-  Repaint();
+  myMainWindow->onFitAll();
 }
 
 //----------------------------------------------------------------
@@ -519,15 +247,7 @@ void
 SVTK_ViewWindow
 ::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();
+  myView->onSelectionChanged();
 }
 
 //----------------------------------------------------------------
@@ -535,8 +255,7 @@ void
 SVTK_ViewWindow
 ::SetSelectionMode(Selection_Mode theMode)
 {
-  mySelector->SetSelectionMode(theMode);
-  myRWInteractor->SetSelectionMode(theMode);
+  myMainWindow->SetSelectionMode( theMode );
 }
 
 //----------------------------------------------------------------
@@ -544,7 +263,7 @@ Selection_Mode
 SVTK_ViewWindow
 ::SelectionMode() const
 {
-  return mySelector->SelectionMode();
+  return myMainWindow->SelectionMode();
 }
 
 //----------------------------------------------------------------
@@ -552,43 +271,17 @@ void
 SVTK_ViewWindow
 ::unHighlightAll() 
 {
-  myRWInteractor->unHighlightAll();
+  myView->unHighlightAll();
 }
 
 //----------------------------------------------------------------
 void
 SVTK_ViewWindow
-::highlight( const Handle(SALOME_InteractiveObject)& theIO, 
-            bool theIsHighlight, 
-            bool theIsUpdate ) 
+::highlight(const Handle(SALOME_InteractiveObject)& theIO, 
+           bool theIsHighlight, 
+           bool theIsUpdate ) 
 {
-  myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
-
-  if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
-    TColStd_IndexedMapOfInteger aMapIndex;
-    mySelector->GetIndex(theIO,aMapIndex);
-    using namespace VTK;
-    const char* anEntry = theIO->getEntry();
-    vtkActorCollection* aCollection = myRenderer->GetActors();
-    if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
-      switch (mySelector->SelectionMode()) {
-      case NodeSelection:
-       myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
-       break;
-      case EdgeOfCellSelection:
-       myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
-       break;
-      case CellSelection:
-      case EdgeSelection:
-      case FaceSelection:
-      case VolumeSelection:
-       myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
-       break;
-      }
-    }
-  }else{
-    myRWInteractor->unHighlightSubSelection();
-  }
+  myView->highlight( theIO, theIsHighlight, theIsUpdate );
 }
 
 //----------------------------------------------------------------
@@ -596,7 +289,7 @@ bool
 SVTK_ViewWindow
 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) 
 {
-  return myRWInteractor->isInViewer( theIO );
+  return myView->isInViewer( theIO );
 }
 
 //----------------------------------------------------------------
@@ -604,7 +297,45 @@ bool
 SVTK_ViewWindow
 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) 
 {
-  return myRWInteractor->isVisible( theIO );
+  return myView->isVisible( theIO );
+}
+
+//----------------------------------------------------------------
+void
+SVTK_ViewWindow
+::Display(const Handle(SALOME_InteractiveObject)& theIO,
+         bool theImmediatly) 
+{
+  myView->Display(theIO,theImmediatly);
+}
+
+void
+SVTK_ViewWindow
+::Erase(const Handle(SALOME_InteractiveObject)& theIO,
+         bool theImmediatly) 
+{
+  myView->Erase(theIO,theImmediatly);
+}
+
+void
+SVTK_ViewWindow
+::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO) 
+{
+  myView->DisplayOnly(theIO);
+}
+
+void 
+SVTK_ViewWindow
+::DisplayAll() 
+{
+  myView->DisplayAll();
+}
+
+void 
+SVTK_ViewWindow
+::EraseAll() 
+{
+  myView->EraseAll();
 }
 
 //----------------------------------------------------------------------------
@@ -612,8 +343,7 @@ void
 SVTK_ViewWindow
 ::setBackgroundColor( const QColor& color )
 {
-  if ( myRenderer )
-    myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
+  myMainWindow->SetBackgroundColor( color );
 }
 
 //----------------------------------------------------------------------------
@@ -621,12 +351,7 @@ QColor
 SVTK_ViewWindow
 ::backgroundColor() const
 {
-  float backint[3];
-  if ( myRenderer ) {
-    myRenderer->GetBackground( backint );
-    return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
-  }
-  return SUIT_ViewWindow::backgroundColor();
+  return myMainWindow->BackgroundColor();
 }
 
 //----------------------------------------------------------------------------
@@ -634,9 +359,7 @@ void
 SVTK_ViewWindow
 ::Repaint(bool theUpdateTrihedron)
 {
-  if (theUpdateTrihedron) 
-    onAdjustTrihedron();
-  myRenderWindow->update();
+  myMainWindow->Repaint( theUpdateTrihedron );
 }
 
 //----------------------------------------------------------------------------
@@ -644,7 +367,7 @@ void
 SVTK_ViewWindow
 ::GetScale( double theScale[3] ) 
 {
-  myTransform->GetMatrixScale( theScale );
+  myMainWindow->GetScale( theScale );
 }
 
 //----------------------------------------------------------------------------
@@ -652,9 +375,7 @@ void
 SVTK_ViewWindow
 ::SetScale( double theScale[3] ) 
 {
-  myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
-  myRWInteractor->Render();
-  Repaint();
+  myMainWindow->SetScale( theScale );
 }
 
 //----------------------------------------------------------------------------
@@ -662,14 +383,14 @@ bool
 SVTK_ViewWindow
 ::isTrihedronDisplayed()
 {
-  return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+  return myMainWindow->IsTrihedronDisplayed();
 }
 
 bool
 SVTK_ViewWindow
 ::isCubeAxesDisplayed()
 {
-  return myCubeAxes->GetVisibility() == 1;
+  return myMainWindow->IsCubeAxesDisplayed();
 }
 
 //----------------------------------------------------------------------------
@@ -677,80 +398,43 @@ void
 SVTK_ViewWindow
 ::onViewTrihedron()
 {
-  if(!myTrihedron) 
-    return;
-
-  if(isTrihedronDisplayed())
-    myTrihedron->VisibilityOff();
-  else
-    myTrihedron->VisibilityOn();
-
-  Repaint();
+  myMainWindow->onViewTrihedron();
 }
 
 void
 SVTK_ViewWindow
 ::onViewCubeAxes()
 {
-  if(!myCubeAxes)
-    return;
-
-  if(isCubeAxesDisplayed())
-    myCubeAxes->VisibilityOff();
-  else
-    myCubeAxes->VisibilityOn();
-
-  Repaint();
+  myMainWindow->onViewCubeAxes();
 }
 
 //----------------------------------------------------------------------------
-/*bool
-SVTK_ViewWindow
-::ComputeTrihedronSize( double& theNewSize, double& theSize )
+VTKViewer_Trihedron* 
+SVTK_ViewWindow::
+GetTrihedron()
 {
-  // calculating diagonal of visible props of the renderer
-  float aBndBox[ 6 ];
-  myTrihedron->VisibilityOff();
-
-  if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
-    aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
-    aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
-  }
-
-  myTrihedron->VisibilityOn();
-  float aLength = 0;
-  static bool aCalcByDiag = false;
-  if ( aCalcByDiag ) {
-    aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
-                    ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
-                    ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
-  } else {
-    aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
-    aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
-    aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
-  }
-
-  float aSizeInPercents = myTrihedronSize;
-
-  static float EPS_SIZE = 5.0E-3;
-  theSize = myTrihedron->GetSize();
-  theNewSize = aLength * aSizeInPercents / 100.0;
+  return myMainWindow->GetTrihedron();
+}
 
-  // if the new trihedron size have sufficient difference, then apply the value
-  return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
-         fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
-}*/
+SVTK_CubeAxesActor2D* 
+SVTK_ViewWindow
+::GetCubeAxes()
+{
+  return myMainWindow->GetCubeAxes();
+}
 
-//----------------------------------------------------------------------------
-int SVTK_ViewWindow::GetTrihedronSize() const
+int
+SVTK_ViewWindow
+::GetTrihedronSize() const
 {
-  return myTrihedronSize;
+  return myMainWindow->GetTrihedronSize();
 }
 
-void SVTK_ViewWindow::SetTrihedronSize( const int sz )
+void
+SVTK_ViewWindow
+::SetTrihedronSize(const int theSize)
 {
-  myTrihedronSize = sz;
-  AdjustTrihedrons( true );
+  myMainWindow->SetTrihedronSize(theSize);
 }
 
 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
@@ -760,81 +444,7 @@ void
 SVTK_ViewWindow
 ::AdjustTrihedrons(const bool theIsForcedUpdate)
 {
-  if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
-    return;
-
-  float bnd[ 6 ];
-  float newbnd[6];
-  newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
-  newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
-
-  myCubeAxes->GetBounds(bnd);
-
-  int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
-
-  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
-  bool isRelativeSize = aResMgr->booleanValue( "VTKViewer", "relative_size", true );
-  
-  //if (aVisibleNum || theIsForcedUpdate) {
-  if (aVisibleNum || !isRelativeSize) {
-    // if the new trihedron size have sufficient difference, then apply the value
-    double aNewSize = 100, anOldSize=myTrihedron->GetSize();
-    bool aTDisplayed = isTrihedronDisplayed();
-    bool aCDisplayed = isCubeAxesDisplayed();
-    if(aTDisplayed) myTrihedron->VisibilityOff();
-    if(aCDisplayed) myCubeAxes->VisibilityOff();
-
-    int aDefaultSize = 100;
-    if (isRelativeSize) aDefaultSize = 105;
-    int aSizeFromPreferences = aResMgr->integerValue( "VTKViewer", "trihedron_size", aDefaultSize );
-    
-    //bool isComputeTrihedronSize =
-    if (isRelativeSize)
-      ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, (float)aSizeFromPreferences);
-    else
-      aNewSize = (double)aSizeFromPreferences;
-    
-    myTrihedron->SetSize( aNewSize );
-
-    // iterate through displayed objects and set size if necessary
-    vtkActorCollection* anActors = getRenderer()->GetActors();
-    anActors->InitTraversal();
-    while (vtkActor* anActor = anActors->GetNextActor())
-    {
-      if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
-      {
-       if (aSActor->IsResizable())
-         aSActor->SetSize( 0.5 * aNewSize );
-        if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
-         float *abounds = aSActor->GetBounds();
-          if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
-              abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
-              abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
-           for (int i = 0; i < 5; i = i + 2) {
-             if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
-             if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
-           }
-        }
-      }
-    }
-    if (aTDisplayed) myTrihedron->VisibilityOn();
-    if (aCDisplayed) myCubeAxes->VisibilityOn();
-    
-  } else {
-     double aSize = myTrihedron->GetSize();
-     newbnd[0] = newbnd[2] = newbnd[4] = 0;
-     newbnd[1] = newbnd[3] = newbnd[5] = aSize;
-  }
-  
-  if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
-      newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
-    for(int i=0;i<6;i++) bnd[i] = newbnd[i];
-    myCubeAxes->SetBounds(bnd);
-  }
-  
-  myCubeAxes->SetBounds(bnd);
-
-  ::ResetCameraClippingRange(myRenderer);
+  myMainWindow->AdjustActors();
 }
 
 //----------------------------------------------------------------------------
@@ -842,115 +452,14 @@ void
 SVTK_ViewWindow
 ::onAdjustTrihedron()
 {   
-  AdjustTrihedrons( false );
+  myMainWindow->onAdjustTrihedron();
 }
 
 void
 SVTK_ViewWindow
 ::onAdjustCubeAxes()
 {   
-  AdjustTrihedrons(false);
-}
-
-#define INCREMENT_FOR_OP 10
-
-//=======================================================================
-// name    : onPanLeft
-// Purpose : Performs incremental panning to the left
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanLeft()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
-}
-
-//=======================================================================
-// name    : onPanRight
-// Purpose : Performs incremental panning to the right
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanRight()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
-}
-
-//=======================================================================
-// name    : onPanUp
-// Purpose : Performs incremental panning to the top
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanUp()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
-}
-
-//=======================================================================
-// name    : onPanDown
-// Purpose : Performs incremental panning to the bottom
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanDown()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
-}
-
-//=======================================================================
-// name    : onZoomIn
-// Purpose : Performs incremental zooming in
-//=======================================================================
-void
-SVTK_ViewWindow
-::onZoomIn()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
-}
-
-//=======================================================================
-// name    : onZoomOut
-// Purpose : Performs incremental zooming out
-//=======================================================================
-void
-SVTK_ViewWindow
-::onZoomOut()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
-}
-
-//=======================================================================
-// name    : onRotateLeft
-// Purpose : Performs incremental rotating to the left
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateLeft()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
-}
-
-//=======================================================================
-// name    : onRotateRight
-// Purpose : Performs incremental rotating to the right
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateRight()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
-}
-
-//=======================================================================
-// name    : onRotateUp
-// Purpose : Performs incremental rotating to the top
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateUp()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
+  myMainWindow->onAdjustCubeAxes();
 }
 
 //=======================================================================
@@ -1001,140 +510,90 @@ SVTK_ViewWindow
   emit mouseDoubleClicked( this, event );
 }
 
-//=======================================================================
-// name    : onRotateDown
-// Purpose : Performs incremental rotating to the bottom
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateDown()
-{
-  myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
-}
-
 //----------------------------------------------------------------------------
 void
 SVTK_ViewWindow
-::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
+::AddActor( VTKViewer_Actor* theActor, 
+           bool theUpdate )
 {
-  theActor->AddToRender(myRenderer);
-  theActor->SetTransform(myTransform);
-  if(theMoveInternalActors) 
-    myRWInteractor->MoveInternalActors();
+  myMainWindow->AddActor( theActor, theUpdate );
 }
 
 //----------------------------------------------------------------------------
 void
 SVTK_ViewWindow
-::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
+::RemoveActor( VTKViewer_Actor* theActor, 
+              bool theUpdate )
 {
-  InsertActor(theActor);
-  if(theUpdate) 
-    Repaint();
+  myMainWindow->RemoveActor( theActor, theUpdate );
 }
 
 //----------------------------------------------------------------------------
-void
+QImage
 SVTK_ViewWindow
-::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
+::dumpView()
 {
-  theActor->RemoveFromRender(myRenderer);
-  if(theUpdate) 
-    Repaint();
+  return myMainWindow->dumpView();
 }
 
 //----------------------------------------------------------------------------
 void
 SVTK_ViewWindow
-::MoveActor( SALOME_Actor* theActor)
+::SetSelectionProp(const double& theRed, 
+                  const double& theGreen, 
+                  const double& theBlue, 
+                  const int& theWidth) 
 {
-  RemoveActor(theActor);
-  InsertActor(theActor,true);
+  myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
 }
 
 //----------------------------------------------------------------------------
-QImage
+void
 SVTK_ViewWindow
-::dumpView()
+::SetPreselectionProp(const double& theRed, 
+                     const double& theGreen, 
+                     const double& theBlue, 
+                     const int& theWidth) 
 {
-  QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
-  return px.convertToImage();
+  myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
 }
 
 //----------------------------------------------------------------------------
-void 
+void
 SVTK_ViewWindow
-::action( const int theAction  )
+::SetSelectionTolerance(const double& theTolNodes, 
+                       const double& theTolItems)
 {
-  switch ( theAction ) {
-  case SUIT_Accel::PanLeft     : onPanLeft();     break;
-  case SUIT_Accel::PanRight    : onPanRight();    break;
-  case SUIT_Accel::PanUp       : onPanUp();       break;
-  case SUIT_Accel::PanDown     : onPanDown();     break;
-  case SUIT_Accel::ZoomIn      : onZoomIn();      break;
-  case SUIT_Accel::ZoomOut     : onZoomOut();     break;
-  case SUIT_Accel::ZoomFit     : onFitAll();      break;
-  case SUIT_Accel::RotateLeft  : onRotateLeft();  break;
-  case SUIT_Accel::RotateRight : onRotateRight(); break;
-  case SUIT_Accel::RotateUp    : onRotateUp();    break;
-  case SUIT_Accel::RotateDown  : onRotateDown();  break;
-  }   
+  myView->SetSelectionTolerance(theTolNodes,theTolItems);
 }
 
-
 //----------------------------------------------------------------------------
-/*! The method returns the visual parameters of this view as a formated string
- */
-QString
-SVTK_ViewWindow
-::getVisualParameters()
+int convertAction( const int accelAction )
 {
-  double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
-
-  vtkCamera* camera = myRenderer->GetActiveCamera();
-  camera->GetPosition( pos );
-  camera->GetFocalPoint( focalPnt );
-  camera->GetViewUp( viewUp );
-  parScale = camera->GetParallelScale();
-  GetScale( scale );
-
-  QString retStr;
-  retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", 
-                 pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1], 
-                 viewUp[2], parScale, scale[0], scale[1], scale[2] );
-  return retStr;
+  switch ( accelAction ) {
+  case SUIT_Accel::PanLeft     : return SVTK::PanLeftEvent;
+  case SUIT_Accel::PanRight    : return SVTK::PanRightEvent;
+  case SUIT_Accel::PanUp       : return SVTK::PanUpEvent;
+  case SUIT_Accel::PanDown     : return SVTK::PanDownEvent;
+  case SUIT_Accel::ZoomIn      : return SVTK::ZoomInEvent;
+  case SUIT_Accel::ZoomOut     : return SVTK::ZoomOutEvent;
+  case SUIT_Accel::RotateLeft  : return SVTK::RotateLeftEvent;
+  case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
+  case SUIT_Accel::RotateUp    : return SVTK::RotateUpEvent;
+  case SUIT_Accel::RotateDown  : return SVTK::RotateDownEvent;  
+  }
+  return accelAction;
 }
 
 //----------------------------------------------------------------------------
-/* The method restors visual parameters of this view from a formated string
- */
 void 
 SVTK_ViewWindow
-::setVisualParameters( const QString& parameters )
+::action( const int accelAction  )
 {
-  QStringList paramsLst = QStringList::split( '*', parameters, true );
-  if ( paramsLst.size() == 13 ) {
-    double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
-    pos[0] = paramsLst[0].toDouble();
-    pos[1] = paramsLst[1].toDouble();
-    pos[2] = paramsLst[2].toDouble();
-    focalPnt[0] = paramsLst[3].toDouble();
-    focalPnt[1] = paramsLst[4].toDouble();
-    focalPnt[2] = paramsLst[5].toDouble();
-    viewUp[0] = paramsLst[6].toDouble();
-    viewUp[1] = paramsLst[7].toDouble();
-    viewUp[2] = paramsLst[8].toDouble();
-    parScale = paramsLst[9].toDouble();
-    scale[0] = paramsLst[10].toDouble();
-    scale[1] = paramsLst[11].toDouble();
-    scale[2] = paramsLst[12].toDouble();
-
-    vtkCamera* camera = myRenderer->GetActiveCamera();
-    camera->SetPosition( pos );
-    camera->SetFocalPoint( focalPnt );
-    camera->SetViewUp( viewUp );
-    camera->SetParallelScale( parScale );
-    myTransform->SetMatrixScale( scale[0], scale[1], scale[2] );
-    myRWInteractor->Render();
+  if ( accelAction == SUIT_Accel::ZoomFit )
+    onFitAll();
+  else {
+    int anEvent = convertAction( accelAction );
+    myMainWindow->InvokeEvent( anEvent, 0 );
   }
 }
index b306ee3adccda311569cfd8e74168d15146db491..1fc559c78145aea29e4d99de0a916e077ac778eb 100755 (executable)
 #endif
 
 #include "SVTK.h"
-#include "SUIT_ViewWindow.h"
-
 #include "SVTK_Selection.h"
+#include "SUIT_ViewWindow.h"
 #include "SALOME_InteractiveObject.hxx"
 
-class vtkRenderer;
-
-class QtxAction;
 class SUIT_Desktop;
 
+class VTKViewer_Actor;
 class VTKViewer_Trihedron;
-class VTKViewer_Transform;
-
-class SALOME_Actor;
 
-class SVTK_Viewer;
+class SVTK_ViewModelBase;
+class SVTK_MainWindow;
 class SVTK_Selector;
+class SVTK_View;
+
+class SVTK_InteractorStyle;
 class SVTK_CubeAxesActor2D;
 
 class SVTK_RenderWindow;
-class SVTK_InteractorStyle;
 class SVTK_RenderWindowInteractor;
 
+class vtkRenderer;
+class vtkRenderWindow;
+class vtkRenderWindowInteractor;
+
+//! Define a container for SALOME VTK view window
 class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
 {
   Q_OBJECT;
 
-public:
-  SVTK_ViewWindow( SUIT_Desktop*, SVTK_Viewer* );
-  virtual ~SVTK_ViewWindow();
+ public:
+  //! To construct #SVTK_ViewWindow instance
+  SVTK_ViewWindow(SUIT_Desktop* theDesktop);
+
+  virtual
+  ~SVTK_ViewWindow();
   
-  QToolBar* getToolBar() { return myToolBar; }
+  //! To initialize #SVTK_ViewWindow instance
+  virtual
+  void
+  Initialize(SVTK_ViewModelBase* theModel);
+
+  //! Get #SVTK_View
+  SVTK_View* 
+  getView();
+
+  //! Get #SVTK_MainWindow
+  SVTK_MainWindow* 
+  getMainWindow();
+
+  //! Redirect the request to #SVTK_MainWindow::getRenderWindow
+  vtkRenderWindow* 
+  getRenderWindow();
+
+  //! Redirect the request to #SVTK_MainWindow::getInteractor
+  vtkRenderWindowInteractor*
+  getInteractor();
+
+  //! Redirect the request to #SVTK_MainWindow::getRenderer 
+  vtkRenderer* 
+  getRenderer();
+
+  //! Redirect the request to #SVTK_MainWindow::GetSelector 
+  SVTK_Selector* 
+  GetSelector();
   
-  void setBackgroundColor( const QColor& );
-  QColor backgroundColor() const;
-
-  vtkRenderer* getRenderer() {return myRenderer;}
-  SVTK_Selector* GetSelector() {return mySelector;}
-  SVTK_RenderWindow* getRenderWindow() {return myRenderWindow;}
-  SVTK_RenderWindowInteractor* getRWInteractor() {return myRWInteractor;}
-  Selection_Mode SelectionMode() const;
-  void SetSelectionMode(Selection_Mode theMode);
-
-  bool isTrihedronDisplayed();
-  bool isCubeAxesDisplayed();
+  //! Redirect the request to #SVTK_Selector::SelectionMode
+  Selection_Mode
+  SelectionMode() const;
+  
+  //! Change selection mode
+  virtual
+  void
+  SetSelectionMode(Selection_Mode theMode);
+
+  //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor 
+  virtual
+  void
+  setBackgroundColor( const QColor& );
+
+  //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor 
+  QColor
+  backgroundColor() const;
+
+  //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
+  bool
+  isTrihedronDisplayed();
+
+  //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
+  bool
+  isCubeAxesDisplayed();
  
   /*  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 );
+  //! Redirect the request to #SVTK_View::highlight (to support old code)
+  virtual
+  void
+  highlight(const Handle(SALOME_InteractiveObject)& theIO, 
+           bool theIsHighlight = true, 
+           bool theIsUpdate = true);
+
+  //! Redirect the request to #SVTK_View::unHighlightAll (to support old code)
+  virtual
+  void
+  unHighlightAll();
+
+  //! Redirect the request to #SVTK_View::isInViewer (to support old code)
+  bool
+  isInViewer(const Handle(SALOME_InteractiveObject)& theIObject);
+
+  //! Redirect the request to #SVTK_View::isVisible (to support old code)
+  bool
+  isVisible(const Handle(SALOME_InteractiveObject)& theIObject);
 
   /* selection */
-  Handle(SALOME_InteractiveObject) FindIObject(const char* Entry);
+  //----------------------------------------------------------------------------
+  Handle(SALOME_InteractiveObject) 
+  FindIObject(const char* theEntry);
   
   /* 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 SetScale( double theScale[3] );
-  void GetScale( double theScale[3] );
-  void AddActor( SALOME_Actor*, bool update = false );
-  void RemoveActor(SALOME_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 );
-
-  int  GetTrihedronSize() const;
-  void SetTrihedronSize( const int );
-
-  VTKViewer_Trihedron*  GetTrihedron() {return this->myTrihedron;};
-  SVTK_CubeAxesActor2D* GetCubeAxes() {return this->myCubeAxes;};
-
-  virtual QString   getVisualParameters();
-  virtual void      setVisualParameters( const QString& parameters );
-
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_View::Display (to support old code)
+  virtual
+  void
+  Display(const Handle(SALOME_InteractiveObject)& theIObject,
+         bool theImmediatly = true);
+
+  //! Redirect the request to #SVTK_View::DisplayOnly (to support old code)
+  virtual
+  void
+  DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject);
+
+  //! Redirect the request to #SVTK_View::Erase (to support old code)
+  virtual
+  void
+  Erase(const Handle(SALOME_InteractiveObject)& theIObject,
+       bool theImmediatly = true);
+
+  //! Redirect the request to #SVTK_View::DisplayAll (to support old code)
+  virtual
+  void 
+  DisplayAll();
+
+  //! Redirect the request to #SVTK_View::EraseAll (to support old code)
+  virtual
+  void 
+  EraseAll();
+
+  //! To repaint the viewer
+  virtual
+  void
+  Repaint(bool theUpdateTrihedron = true);
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_Renderer::SetScale
+  virtual
+  void 
+  SetScale( double theScale[3] );
+
+  //! Redirect the request to #SVTK_Renderer::GetScale
+  virtual
+  void
+  GetScale( double theScale[3] );
+
+  //! Redirect the request to #SVTK_Renderer::AddActor
+  virtual
+  void
+  AddActor(VTKViewer_Actor* theActor,
+          bool theIsUpdate = false);
+
+  //! Redirect the request to #SVTK_Renderer::RemoveActor
+  virtual
+  void
+  RemoveActor(VTKViewer_Actor* theActor,
+             bool theIsUpdate = false);
+
+  //----------------------------------------------------------------------------
+  //! Redirect the request to #SVTK_Renderer::AdjustActors
+  virtual
+  void
+  AdjustTrihedrons(const bool theIsForced);
+
+  //! Redirect the request to #SVTK_Renderer::GetTrihedron
+  VTKViewer_Trihedron*  
+  GetTrihedron();
+
+  //! Redirect the request to #SVTK_Renderer::GetCubeAxes
+  SVTK_CubeAxesActor2D* 
+  GetCubeAxes();
+
+  //! Redirect the request to #SVTK_Renderer::GetTrihedronSize
+  int  
+  GetTrihedronSize() const;
+
+  //! Redirect the request to #SVTK_Renderer::SetTrihedronSize
+  virtual
+  void 
+  SetTrihedronSize( const int );
+
+  //! Redirect the request to #SVTK_Renderer::SetSelectionProp
+  virtual
+  void
+  SetSelectionProp(const double& theRed = 1, 
+                  const double& theGreen = 1,
+                  const double& theBlue = 0, 
+                  const int& theWidth = 5);
+
+  //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
+  virtual
+  void
+  SetPreselectionProp(const double& theRed = 0, 
+                     const double& theGreen = 1,
+                     const double& theBlue = 1, 
+                     const int& theWidth = 5);
+
+  //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance
+  virtual
+  void
+  SetSelectionTolerance(const double& theTolNodes = 0.025, 
+                       const double& theTolCell = 0.001);
+  
 public slots:
-  void onSelectionChanged();
+  virtual
+  void
+  onSelectionChanged();
 
 signals:
  void selectionChanged();
 
 public slots:
-  void onFrontView(); 
-  void onBackView(); 
-  void onTopView();
-  void onBottomView();
-  void onRightView(); 
-  void onLeftView();     
-
-  void onResetView();     
-  void onFitAll();
-
-  void onViewTrihedron(); 
-  void onViewCubeAxes();
-
-  void onAdjustTrihedron();
-  void onAdjustCubeAxes();
-  void onPanLeft();
-  void onPanRight();
-  void onPanUp();
-  void onPanDown();
-  void onZoomIn();
-  void onZoomOut();
-  void onRotateLeft();
-  void onRotateRight();
-  void onRotateUp();
-  void onRotateDown();
-
-  void activateZoom();
-  void activateWindowFit();
-  void activateRotation();
-  void activatePanning(); 
-  void activateGlobalPanning(); 
-
-protected:
-  QImage dumpView();
-  virtual void      action( const int );
+  //! Redirect the request to #SVTK_Renderer::OnFrontView
+  virtual
+  void
+  onFrontView(); 
+
+  //! Redirect the request to #SVTK_Renderer::OnBackView
+  virtual
+  void
+  onBackView(); 
+
+  //! Redirect the request to #SVTK_Renderer::OnTopView
+  virtual
+  void
+  onTopView();
+
+  //! Redirect the request to #SVTK_Renderer::OnBottomView
+  virtual
+  void
+  onBottomView();
+
+  //! Redirect the request to #SVTK_Renderer::OnRightView
+  virtual
+  void 
+  onRightView(); 
+
+  //! Redirect the request to #SVTK_Renderer::OnLeftView
+  virtual
+  void 
+  onLeftView();     
+
+  //! Redirect the request to #SVTK_Renderer::OnResetView
+  virtual
+  void
+  onResetView();     
+
+  //! Redirect the request to #SVTK_Renderer::OnFitAll
+  virtual
+  void 
+  onFitAll();
+
+  //! Redirect the request to #SVTK_Renderer::OnViewTrihedron
+  virtual
+  void
+  onViewTrihedron(); 
+
+  //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes
+  virtual
+  void
+  onViewCubeAxes();
+
+  //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
+  virtual
+  void
+  onAdjustTrihedron();
+
+  //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
+  virtual
+  void 
+  onAdjustCubeAxes();
 
 protected slots:
   void onKeyPressed(QKeyEvent* event);
@@ -162,39 +320,18 @@ protected slots:
   void onMouseReleased(QMouseEvent* event);
   void onMouseMoving(QMouseEvent* event);
 
-private:
-  void InitialSetup();
-  void InsertActor( SALOME_Actor* theActor,
-                    bool theMoveInternalActors = false );
-  void MoveActor( SALOME_Actor* theActor );
-
-private:  
-  enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId,
-         FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId };
-  typedef QMap<int, QtxAction*> ActionsMap;
-  
-  void createActions();
-  void createToolBar();
-  
-  vtkRenderer* myRenderer;
-
-  SVTK_Viewer* myModel;
-  SVTK_Selector* mySelector;
-
-  SVTK_RenderWindow* myRenderWindow;
-  SVTK_RenderWindowInteractor* myRWInteractor;
+protected:
+  virtual
+  void
+  Initialize(SVTK_View* theView,
+            SVTK_ViewModelBase* theModel);
 
-  VTKViewer_Transform*  myTransform;
-  VTKViewer_Trihedron*  myTrihedron;  
-  int                   myTrihedronSize;
-  SVTK_CubeAxesActor2D* myCubeAxes;
-  
-  QToolBar* myToolBar;
-  ActionsMap myActionsMap;  
-  
-  double myCurScale;
+  QImage dumpView();
+  virtual void action( const int );
 
-  friend class SVTK_RenderWindowInteractor;
+  SVTK_View* myView;
+  SVTK_MainWindow* myMainWindow;
+  SVTK_ViewModelBase* myModel;
 };
 
 #ifdef WIN32