]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
MPV: Merge V1.2c
authorsmh <smh@opencascade.com>
Mon, 26 Jan 2004 14:08:38 +0000 (14:08 +0000)
committersmh <smh@opencascade.com>
Mon, 26 Jan 2004 14:08:38 +0000 (14:08 +0000)
12 files changed:
src/VTKViewer/Makefile.in
src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx
src/VTKViewer/VTKViewer_InteractorStyleSALOME.h
src/VTKViewer/VTKViewer_RenderWindow.cxx
src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx
src/VTKViewer/VTKViewer_RenderWindowInteractor.h
src/VTKViewer/VTKViewer_Trihedron.cxx [new file with mode: 0644]
src/VTKViewer/VTKViewer_Trihedron.h [new file with mode: 0644]
src/VTKViewer/VTKViewer_Utilities.cxx [new file with mode: 0644]
src/VTKViewer/VTKViewer_Utilities.h [new file with mode: 0644]
src/VTKViewer/VTKViewer_ViewFrame.cxx
src/VTKViewer/VTKViewer_ViewFrame.h

index 3d562442d2867b40b2a99e2208d12194db09973a..0733c58b9711ee4cb49890f8b6832c9a956f1c00 100644 (file)
@@ -47,7 +47,9 @@ LIB_SRC= VTKViewer.cxx \
         VTKViewer_RenderWindow.cxx \
         VTKViewer_RenderWindowInteractor.cxx \
         VTKViewer_InteractorStyleSALOME.cxx \
-        VTKViewer_VectorText.cxx
+        VTKViewer_Trihedron.cxx \
+        VTKViewer_VectorText.cxx \
+        VTKViewer_Utilities.cxx
 
 LIB_MOC = \
         VTKViewer.h \
index b0cfe0abb33102f28d92d11dc6214ce37e6c9295..329e055acb0f731bdfec14ebdcfef92737bc510b 100644 (file)
 //  Module : SALOME
 //  $Header$
 
-using namespace std;
 #include "VTKViewer_InteractorStyleSALOME.h"
 #include "VTKViewer_RenderWindow.h"
+#include "VTKViewer_Utilities.h"
+#include "VTKViewer_Trihedron.h"
 
-#include <qapplication.h>
 #include "QAD_Config.h"
 #include "QAD_Application.h"
 #include "QAD_Desktop.h"
@@ -54,31 +54,25 @@ using namespace std;
 #include <vtkImageData.h>
 #include <vtkFollower.h>
 
-
+#include <qapplication.h>
 //VRV: porting on Qt 3.0.5
 #if QT_VERSION >= 0x030005
 #include <qpainter.h>
 #endif
 //VRV: porting on Qt 3.0.5
 
-//----------------------------------------------------------------------------
-VTKViewer_InteractorStyleSALOME *VTKViewer_InteractorStyleSALOME::New() 
-{
-  // First try to create the object from the vtkObjectFactory
-  vtkObject* ret = vtkObjectFactory::CreateInstance("VTKViewer_InteractorStyleSALOME");
-  if(ret)
-    {
-      return (VTKViewer_InteractorStyleSALOME*)ret;
-    }
-  // If the factory was unable to create the object, then create it here.
-  return new VTKViewer_InteractorStyleSALOME;
-}
+using namespace std;
 
+extern int SetVisibility(vtkActorCollection* theCollection, int theParam);
+extern int GetVisibility(vtkActorCollection* theCollection);
 
 //----------------------------------------------------------------------------
+vtkStandardNewMacro(VTKViewer_InteractorStyleSALOME);
+//----------------------------------------------------------------------------
+
 VTKViewer_InteractorStyleSALOME::VTKViewer_InteractorStyleSALOME() 
 {
-  m_Triedron = 0;
+  m_Trihedron = 0;
   this->MotionFactor = 10.0;
   this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
   this->RadianToDegree = 180.0 / vtkMath::Pi();
@@ -92,9 +86,8 @@ VTKViewer_InteractorStyleSALOME::~VTKViewer_InteractorStyleSALOME()
 }
 
 //----------------------------------------------------------------------------
-void VTKViewer_InteractorStyleSALOME::setTriedron( vtkActorCollection* triedron )
-{
-  m_Triedron = triedron;
+void VTKViewer_InteractorStyleSALOME::setTriedron(VTKViewer_Trihedron* theTrihedron){
+  m_Trihedron = theTrihedron;
 }
 
 //----------------------------------------------------------------------------
@@ -120,15 +113,8 @@ void VTKViewer_InteractorStyleSALOME::RotateXY(int dx, int dy)
   cam->Azimuth(rxf);
   cam->Elevation(ryf);
   cam->OrthogonalizeViewUp();
-  this->CurrentRenderer->ResetCameraClippingRange();
-  vtkRenderWindowInteractor *rwi = this->Interactor;
-  /* VSV Light follows camera: if (this->CurrentLight)
-    {
-      // get the first light
-      this->CurrentLight->SetPosition(cam->GetPosition());
-      this->CurrentLight->SetFocalPoint(cam->GetFocalPoint());
-      }        */
-  rwi->Render();
+  ::ResetCameraClippingRange(this->CurrentRenderer); 
+  this->Interactor->Render();
 }
 
 //----------------------------------------------------------------------------
@@ -148,98 +134,26 @@ void VTKViewer_InteractorStyleSALOME::PanXY(int x, int y, int oldX, int oldY)
 
 //----------------------------------------------------------------------------
 void VTKViewer_InteractorStyleSALOME::ControlLblSize(double aOldScale, double aNewScale) {
-  m_Triedron->InitTraversal();
-  vtkActor *ac = m_Triedron->GetNextActor();
-  bool IsConeActor = true;
-  while(!(ac==NULL)) {
-    float aMaxXRange;
-    float aMaxYRange;
-    float aMaxZRange;
-    if(ac->IsA("vtkFollower")) {
-      float aScale[3];
-      ac->GetScale(aScale);
-      
-      float aPosition[3];
-      ac->GetPosition(aPosition);
-      
-      float aPercent = (aOldScale-aNewScale)/aOldScale;
-      ac->SetScale(aScale[0]*(1-aPercent),aScale[1]*(1-aPercent),aScale[2]*(1-aPercent));
-           
-      //Set new position
-      float aLength = ac->GetLength();
-      if (aPosition[0]!=0) {
-       //x
-       aPosition[0] = aMaxXRange;
-      } else if (aPosition[1]!=0) {
-       //y
-       aPosition[1] = aMaxYRange;
-      } else if (aPosition[2]!=0) {
-       //z
-       aPosition[2] = aMaxZRange;
-      }
-      ac->SetPosition(aPosition);
-      
-      IsConeActor = true;
-    }
-    else {
-      if (IsConeActor) {
-       //coneActor is the first in the list (see m_Triedron->AddItem(...) in VTKViewer_ViewFrame::AddVector(...))
-       IsConeActor = false;
-       
-       float aPosition[3];
-       ac->GetPosition(aPosition);
-       
-       if (aPosition[0]!=0) {
-         //x
-         float* aXRange = ac->GetXRange();
-         if (aXRange[0] < aXRange[1]) aMaxXRange = aXRange[1];
-         else aMaxXRange = aXRange[0];
-       } else if (aPosition[1]!=0) {
-         //y
-         float* aYRange = ac->GetYRange();
-         if (aYRange[0] < aYRange[1]) aMaxYRange = aYRange[1];
-         else aMaxYRange = aYRange[0];
-       } else if (aPosition[2]!=0) {
-         //z
-         float* aZRange = ac->GetZRange();
-         if (aZRange[0] < aZRange[1]) aMaxZRange = aZRange[1];
-         else aMaxZRange = aZRange[0];
-       }
-      } 
-    }
-    ac = m_Triedron->GetNextActor();
-  }
+  return;
 }
 
 //----------------------------------------------------------------------------
 void VTKViewer_InteractorStyleSALOME::DollyXY(int dx, int dy)
 {
-  vtkCamera *cam;
+  if (this->CurrentRenderer == 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 zoomFactor = pow((double)1.1, dxf + dyf);
   
-  if (this->CurrentRenderer == NULL)
-    {
-      return;
-    }
-  
-  cam = this->CurrentRenderer->GetActiveCamera();
-    if (cam->GetParallelProjection())
-    {
-      double aOldScale = cam->GetParallelScale();
-      cam->SetParallelScale(cam->GetParallelScale()/zoomFactor);
-      double aNewScale = cam->GetParallelScale();
-
-      // for controlling label size
-      ControlLblSize(aOldScale,aNewScale);
-    }
-    else
-    {
-      cam->Dolly(zoomFactor);
-      this->CurrentRenderer->ResetCameraClippingRange();
-    }
+  vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
+  if (aCam->GetParallelProjection())
+    aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
+  else{
+    aCam->Dolly(zoomFactor);
+    ::ResetCameraClippingRange(this->CurrentRenderer);
+  }
   
   /* VSV Light follows camera: if (this->CurrentLight)
     {      
@@ -597,6 +511,27 @@ void VTKViewer_InteractorStyleSALOME::startFitArea()
   qApp->installEventFilter(this);
 }
 
+
+void  VTKViewer_InteractorStyleSALOME::ViewFitAll() {
+  int aTriedronWasVisible = false;
+  if(m_Trihedron){
+    aTriedronWasVisible = 
+      m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+    if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
+  }
+
+  if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
+    m_Trihedron->VisibilityOff();
+    ::ResetCamera(CurrentRenderer);
+  }else{
+    m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+    ::ResetCamera(CurrentRenderer,true);
+  }
+  if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
+  else m_Trihedron->VisibilityOff();
+}
+
+
 // starts Global Panning operation (e.g. through menu command)
 void VTKViewer_InteractorStyleSALOME::startGlobalPan()
 {
@@ -612,29 +547,21 @@ void VTKViewer_InteractorStyleSALOME::startGlobalPan()
   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
   myScale = cam->GetParallelScale();
 
+  ViewFitAll();
   // make fit all
-  Standard_Boolean TriedronWasVisible = false;
-  if ( m_Triedron ) {
-    m_Triedron->InitTraversal();
-    vtkActor *ac = m_Triedron->GetNextActor();
-    while(!(ac==NULL)) {
-      if(ac->GetVisibility()) {
-       TriedronWasVisible = true;
-       ac->VisibilityOff();
-      }
-      ac = m_Triedron->GetNextActor();
-    }
-  }
-  this->CurrentRenderer->ResetCamera();
-  this->CurrentRenderer->ResetCameraClippingRange();
-  if( m_Triedron && TriedronWasVisible ) {
-    m_Triedron->InitTraversal();
-    vtkActor *ac = m_Triedron->GetNextActor();
-    while(!(ac==NULL)) {
-      ac->VisibilityOn();
-      ac = m_Triedron->GetNextActor();
-    }
-  }
+//   int TriedronWasVisible = false;
+//   if(m_Trihedron){
+//     TriedronWasVisible = 
+//       m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+//     if(TriedronWasVisible) m_Trihedron->VisibilityOff();
+//   }
+
+//   ::ResetCamera(this->CurrentRenderer);
+  
+//   if(m_Trihedron)
+//     if(TriedronWasVisible) 
+//       m_Trihedron->VisibilityOn();
+
   //VTKViewer_RenderWindow* aRW = dynamic_cast<VTKViewer_RenderWindow*>(this->Interactor->GetRenderWindow());
   if (myGUIWindow) myGUIWindow->update();
   
@@ -657,10 +584,7 @@ void VTKViewer_InteractorStyleSALOME::fitRect(const int left,
                                        const int right, 
                                        const int bottom)
 {
-  if (this->CurrentRenderer == NULL) {
-    return;
-  }
-  vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
+  if (this->CurrentRenderer == NULL) return;
  
   // move camera
   int x = (left + right)/2;
@@ -670,17 +594,17 @@ void VTKViewer_InteractorStyleSALOME::fitRect(const int left,
   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 zoomFactor = (dxf + dyf)/2 ;
 
-  if (cam->GetParallelProjection()) {
-    cam->SetParallelScale(cam->GetParallelScale()/zoomFactor);
-  } else {
-    cam->Dolly(zoomFactor);
-    this->CurrentRenderer->ResetCameraClippingRange();
+  vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
+  if(aCam->GetParallelProjection())
+    aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
+  else{
+    aCam->Dolly(zoomFactor);
+    ::ResetCameraClippingRange(this->CurrentRenderer);
   }
   
   //vtkRenderWindowInteractor *rwi = this->Interactor;
@@ -765,6 +689,8 @@ void VTKViewer_InteractorStyleSALOME::setCursor(const int operation)
 void VTKViewer_InteractorStyleSALOME::onStartOperation()
 {
   if (!myGUIWindow) 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:
@@ -789,14 +715,16 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
 {
   if (!myGUIWindow) return;
 
+
   QAD_Study* aActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
   SALOME_Selection* aSel    = SALOME_Selection::Selection( aActiveStudy->getSelection() );
   vtkRenderWindowInteractor *rwi = this->Interactor;
 
+  // VSV: LOD actor activisation
+  //  rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
+
   int aSelectionMode = aSel->SelectionMode();
   bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
-  SALOMEDS::SComponent_var aActiveComponent = SALOMEDS::SComponent::_narrow(
-     aActiveStudy->getStudyDocument()->FindObject(QAD_Application::getDesktop()->getActiveComponent()));
 
   switch (State) {
     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
@@ -829,6 +757,11 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
           vtkActorCollection* listactors = NULL;
           this->FindPokedRenderer(x, y);
          rwi->StartPickCallback();
+
+//       vtkPicker* aPicker = vtkPicker::SafeDownCast(rwi->GetPicker());
+//       if (aPicker)
+//         aPicker->SetTolerance(0.01);
+         
           rwi->GetPicker()->Pick(x, y, 0.0, this->CurrentRenderer);
     
           if ( rwi->GetPicker()->IsA("vtkCellPicker") ) {
@@ -1020,6 +953,10 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
           }
         } else {
           //processing rectangle selection
+         SALOMEDS::SComponent_var aActiveComponent = SALOMEDS::SComponent::
+           _narrow(aActiveStudy->getStudyDocument()->
+                   FindObject(QAD_Application::getDesktop()->getActiveComponent()));
+         if(aSelActiveCompOnly && aActiveComponent->_is_nil()) return;
          rwi->StartPickCallback();
 
          if (!myShiftState) {
@@ -1117,9 +1054,10 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
                    if(SActor->hasIO()) {
                      Handle(SALOME_InteractiveObject) IO = SActor->getIO();
                      if(IO.IsNull()) continue;
-                     if(aSelActiveCompOnly)
+                     if(aSelActiveCompOnly) {
                        if(strcmp(aActiveComponent->ComponentDataType(),IO->getComponentDataType()) != 0)
                          continue;
+                     }
                      if(vtkDataSet* aDataSet = SActor->GetMapper()->GetInput()){
                        for(int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++){
                          if(vtkCell* aCell = aDataSet->GetCell(i)){
@@ -1218,6 +1156,8 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
     }
     break;
   }
+  if (myGUIWindow) myGUIWindow->update();
+
 }
 
 // called during viewer operation when user moves mouse (!put necessary processing here!)
@@ -1382,7 +1322,7 @@ void VTKViewer_InteractorStyleSALOME::Place(const int theX, const int theY)
   // restore zoom scale
   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
   cam->SetParallelScale(myScale);
-  this->CurrentRenderer->ResetCameraClippingRange();
+  ::ResetCameraClippingRange(this->CurrentRenderer);
 
   /* VSV Light follows camera: if (this->CurrentLight) {
     this->CurrentLight->SetPosition(cam->GetPosition());
index a8a9aa206359329d28f5ab9676bdddb99d3edb84..62438e91e2d4fd16f0af7bdcf0c7c42a57601aeb 100644 (file)
@@ -34,6 +34,7 @@
 #include <qcursor.h>
 #include "SALOME_Actor.h"
 
+class VTKViewer_Trihedron;
 
 #define VTK_INTERACTOR_STYLE_CAMERA_NONE    0
 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE  1
@@ -53,7 +54,7 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl
   // programmers.
   static VTKViewer_InteractorStyleSALOME *New();
 
-  void setTriedron( vtkActorCollection* triedron );
+  void setTriedron(VTKViewer_Trihedron* theTrihedron);
 
   vtkTypeMacro(VTKViewer_InteractorStyleSALOME, vtkObject);
   void PrintSelf(ostream& os, vtkIndent indent);
@@ -67,6 +68,8 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl
   void OnRightButtonDown(int ctrl, int shift, int x, int y);
   void OnRightButtonUp  (int ctrl, int shift, int x, int y);
 
+  void  ViewFitAll();
+
  protected:
   VTKViewer_InteractorStyleSALOME();
   ~VTKViewer_InteractorStyleSALOME();
@@ -132,7 +135,7 @@ protected:
   bool         myCursorState;
   bool         myShiftState;
   int ForcedState;
-  vtkActorCollection* m_Triedron;  
+  VTKViewer_Trihedron* m_Trihedron;  
 
   QWidget*     myGUIWindow;
 
index 6072e344b883f9302822b24ca45bada172a5e646..7712ec01e3c700e8543b58c8122eb4006d4e5e23 100644 (file)
@@ -45,6 +45,7 @@ using namespace std;
 #include <vtkRenderWindowInteractor.h>
 #include <vtkRendererCollection.h>
 #include <vtkXOpenGLRenderWindow.h>
+#include <vtkCamera.h>
 
 //#include <GL/gl.h>
 //#include <GL/glu.h>
@@ -64,6 +65,7 @@ VTKViewer_RenderWindow::VTKViewer_RenderWindow(QWidget *parent, const char *name
   myRW->SetDisplayId((void*)x11Display());
   myRW->SetWindowId((void*)winId());
   myRW->DoubleBufferOn();
+  setMouseTracking(true);
 }
 
 VTKViewer_RenderWindow::~VTKViewer_RenderWindow() {
@@ -76,10 +78,23 @@ void VTKViewer_RenderWindow::paintEvent(QPaintEvent* theEvent) {
 }
 
 void VTKViewer_RenderWindow::resizeEvent(QResizeEvent* theEvent) {
-  vtkRenderWindowInteractor* aRWI = myRW->GetInteractor();
-  if (aRWI != NULL)
-    aRWI->SetSize(width(), height());
-  myRW->SetSize(width(), height());
+  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);
+    }
+  }
 }
 
 
index 4099a3fcd19ae5e7d7031a9897ad43e519170c58..2e4ce4b961dcb5fb8b46b4256e109f7f83cc8b8d 100644 (file)
@@ -26,7 +26,6 @@
 //  Module : SALOME
 //  $Header$
 
-using namespace std;
 #include "VTKViewer_RenderWindowInteractor.h"
 #include "VTKViewer_RenderWindow.h"
 #include "VTKViewer_InteractorStyleSALOME.h"
@@ -59,10 +58,11 @@ using namespace std;
 #include <vtkRendererCollection.h>
 #include <vtkPolyDataWriter.h>
 
-
 // QT Includes
 #include <qkeycode.h>
 
+using namespace std;
+
 VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() {
   vtkObject *ret = vtkObjectFactory::CreateInstance("VTKViewer_RenderWindowInteractor") ;
   if( ret ) {
@@ -168,6 +168,13 @@ void VTKViewer_RenderWindowInteractor::Initialize() {
   return ;
 }
 
+
+void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver *theInteractor){
+  myInteractorStyle = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(theInteractor);
+  vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
+}
+
+
 void VTKViewer_RenderWindowInteractor::SetSelectionMode(int mode)
 {
   Cell_Actor->VisibilityOff();
@@ -759,55 +766,38 @@ bool VTKViewer_RenderWindowInteractor::highlight( const Handle(SALOME_Interactiv
                                                  bool hilight, 
                                                  bool update)
 {
-  VTKViewer_InteractorStyleSALOME* aStyle = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
-  if (!aStyle) return false;
-
-  vtkRenderer* aren;
-  for (this->RenderWindow->GetRenderers()->InitTraversal(); 
-       (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
-    vtkActorCollection* theActors = aren->GetActors();
-    theActors->InitTraversal();
-    vtkActor *ac = theActors->GetNextActor();
-    while(!(ac==NULL)) {
-      if ( ac->IsA("SALOME_Actor") ) {
-       SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
-       if ( anActor->hasIO() ) {
-         if ( IObject->isSame( anActor->getIO() ) ) {
-           if ( anActor->GetMapper() == NULL ) {
-             return false;
-           }
-           //highlight or unhilight actors
-           if ( anActor->hasHighlight() ) {
-             anActor->highlight(hilight);
-           } else {
-             if ( anActor->GetVisibility() == 1 ) {
-               if (hilight) {
-                 vtkActor2D *actor2D;
-                 vtkProp3D *prop3D;
-                 if ( (prop3D=vtkProp3D::SafeDownCast(anActor)) != NULL ) {
-                   aStyle->HighlightProp3D(prop3D);
-                 } else if ( (actor2D=vtkActor2D::SafeDownCast(anActor)) != NULL ) {
-                   aStyle->HighlightActor2D(actor2D);
-                 }
-                 //this->InteractorStyle->HighlightProp(anActor);
-               } else {
-                 aStyle->HighlightProp3D(NULL);
-                 aStyle->HighlightActor2D(NULL);
-                 //this->InteractorStyle->HighlightProp(NULL);
-               }
+  VTKViewer_InteractorStyleSALOME* aStyle = 
+    VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
+  if(!aStyle) return false;
+  vtkRendererCollection* aRenColl = this->RenderWindow->GetRenderers();
+  aRenColl->InitTraversal();
+  while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){
+      vtkActorCollection* theActors = aRen->GetActors();
+      theActors->InitTraversal();
+      while(vtkActor *anAct = theActors->GetNextActor()) {
+       if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){
+         if(anActor->hasIO()){
+           if(IObject->isSame(anActor->getIO())){
+             if(anActor->GetMapper() == NULL)
+               return false;
+             //highlight or unhilight actors
+             if(anActor->hasHighlight())
+               anActor->highlight(hilight);
+             else{
+               if(anActor->GetVisibility() == 1 && hilight)
+                 aStyle->HighlightProp(anActor);
+               else if(!hilight)
+                 aStyle->HighlightProp(NULL);
              }
            }
          }
        }
       }
-      ac = theActors->GetNextActor();
     }
-  }
-  if (update) {
+  if(update){
     Render();
     emit RenderWindowModified();
   }
-
   return false;
 }
 
@@ -830,36 +820,32 @@ void VTKViewer_RenderWindowInteractor::Update() {
 }
 
 
-bool VTKViewer_RenderWindowInteractor::unHighlightAll()
-{
-  vtkRenderer* aren;
-  for (this->RenderWindow->GetRenderers()->InitTraversal(); 
-       (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
-    vtkActorCollection* theActors = aren->GetActors();
+bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
+  VTKViewer_InteractorStyleSALOME* aStyle = 
+    VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
+  if(aStyle) aStyle->HighlightProp(NULL);
+  vtkRendererCollection* aRenColl = this->RenderWindow->GetRenderers();
+  aRenColl->InitTraversal();
+  while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){
+    vtkActorCollection* theActors = aRen->GetActors();
     theActors->InitTraversal();
-
-    if ( theActors->IsItemPresent(Point_Actor) != 0 ) 
-      aren->RemoveActor( Point_Actor );
-    if ( theActors->IsItemPresent( Edge_Actor ) != 0 ) 
-      aren->RemoveActor( Edge_Actor ); 
-    if ( theActors->IsItemPresent( Cell_Actor ) != 0 ) 
-      aren->RemoveActor( Cell_Actor );
-
-    vtkActor *ac = theActors->GetNextActor();
-
-    while(!(ac==NULL)) {
-      if ( ac->IsA("SALOME_Actor") ) {
-       SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
-       if ( anActor->hasIO() ) {
+    if(theActors->IsItemPresent(Point_Actor)) 
+      aRen->RemoveActor(Point_Actor);
+    if(theActors->IsItemPresent(Edge_Actor)) 
+      aRen->RemoveActor(Edge_Actor); 
+    if(theActors->IsItemPresent(Cell_Actor)) 
+      aRen->RemoveActor(Cell_Actor);
+    vtkActor *anActor = theActors->GetNextActor();
+    while(vtkActor *anAct = theActors->GetNextActor()) {
+      if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){
+       if(anActor->hasIO()){
          //highlight or unhilight actors
-         if ( anActor->hasHighlight() )
+         if(anActor->hasHighlight())
            anActor->highlight(false);
        }
       }
-      ac = theActors->GetNextActor();
     }
   }
-
   emit RenderWindowModified() ;
   return false;
 }
index 24f7dd62262df5a0c6f15f992864eadf4e16626a..e5fa4088529c8953db29d6d2f77083117cc0e8e7 100644 (file)
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 
-class VTKViewer_RenderWindow;
 class vtkPolyData;
 class vtkPolyDataMapper;
 
+class VTKViewer_RenderWindow;
+class VTKViewer_InteractorStyleSALOME;
+
 // ------------------------------------------------------------
 // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
 // The Signal/Slot mechanism used by Qt requires that QObject 
@@ -66,7 +68,7 @@ public:
 
   static VTKViewer_RenderWindowInteractor *New() ; 
 
-  vtkTypeMacro(vtkRenderWindowInteractor,vtkObject);
+  vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
 
   void PrintSelf(ostream& os, vtkIndent indent);
 
@@ -76,6 +78,11 @@ public:
   // want to have mouse interaction.
   virtual void Initialize();
 
+  virtual void SetInteractorStyle(vtkInteractorObserver *);
+  VTKViewer_InteractorStyleSALOME* GetInteractorStyleSALOME(){
+    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
@@ -174,23 +181,24 @@ public:
   vtkRenderer* GetRenderer();
 
   QWidget* getGUIWindow() {return myGUIWindow;}
-  void setGUIWindow(QWidget* theWin) { myGUIWindow = theWin;}
-
+  void setGUIWindow(QWidget* theWin) {myGUIWindow = theWin;}
+  
   typedef void (*TCreateMapperFun)(vtkPolyData *theSourcePolyData, 
-                                          vtkPolyDataMapper* theMapper, 
-                                          const TColStd_MapOfInteger& theMapIndex);
+                                  vtkPolyDataMapper* theMapper, 
+                                  const TColStd_MapOfInteger& theMapIndex);
  protected:
 
   VTKViewer_RenderWindowInteractor();
   ~VTKViewer_RenderWindowInteractor();
 
+  VTKViewer_InteractorStyleSALOME* myInteractorStyle;
+
   bool highlight(const Handle(SALOME_InteractiveObject)& IObject, 
                 const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun,
                 vtkActor *theActor, bool hilight, bool update );
-  //
+
   // Timer used during various mouse events to figure 
   // out mouse movements. 
-  //
   QTimer *mTimer ;
 
   //CAI: Display mode
@@ -202,14 +210,11 @@ public:
   vtkActor* Edge_Actor; //NB
   vtkActor* Cell_Actor;
   
-  //
   // User for switching to stereo mode.
-  //
   int PositionBeforeStereo[2];
-  //
+
   // Connect/disconnect all slots which allow events on the
   // render window to be passed to the interactor. 
-  //
   void ConnectSlots() ;
   void DisconnectSlots() ;
   void ProcessSlotConnections(bool conn) ;
@@ -227,13 +232,12 @@ public:
   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() ;
+
  signals:
   void RenderWindowModified() ;
 
@@ -243,3 +247,4 @@ public:
 
 #endif
 
diff --git a/src/VTKViewer/VTKViewer_Trihedron.cxx b/src/VTKViewer/VTKViewer_Trihedron.cxx
new file mode 100644 (file)
index 0000000..be2d188
--- /dev/null
@@ -0,0 +1,390 @@
+//  SALOME VTKViewer : 
+//
+//  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_Trihedron.cxx
+//  Author : Alexey PETROV
+//  Module : SALOME
+//  $Header: 
+
+#include "VTKViewer_Trihedron.h"
+#include "utilities.h"
+#include "SALOME_Actor.h"
+
+// VTK Includes
+#include <vtkMath.h>
+#include <vtkMapper.h>
+#include <vtkDataSet.h>
+#include <vtkRenderer.h>
+#include <vtkFollower.h>
+#include <vtkRenderWindow.h>
+#include <vtkObjectFactory.h>
+
+#include <vtkActor.h>
+#include <vtkProperty.h>
+#include <vtkLineSource.h>
+#include <vtkConeSource.h>
+#include <vtkPolyDataMapper.h>
+
+#include "VTKViewer_VectorText.h"
+
+using namespace std;
+
+//==============================================================================
+
+class VTKViewer_UnScaledActor: public vtkFollower{
+  VTKViewer_UnScaledActor(const VTKViewer_UnScaledActor&);
+
+public:
+  vtkTypeMacro(VTKViewer_UnScaledActor,vtkFollower);
+  static VTKViewer_UnScaledActor *New();
+
+  virtual void SetSize(int theSize);
+  virtual void Render(vtkRenderer *theRenderer);
+
+protected:
+  VTKViewer_UnScaledActor();
+  int mySize;
+};
+
+vtkStandardNewMacro(VTKViewer_UnScaledActor);
+
+VTKViewer_UnScaledActor::VTKViewer_UnScaledActor(){}
+
+void VTKViewer_UnScaledActor::Render(vtkRenderer *theRenderer){
+  if(theRenderer){
+    float P[2][3] = {{-1.0, -1.0, 0.0},{+1.0, +1.0, 0.0}};
+    theRenderer->ViewToWorld(P[0][0],P[0][1],P[0][2]);
+    theRenderer->ViewToWorld(P[1][0],P[1][1],P[1][2]);
+    float aWorldDiag = sqrt((P[1][0]-P[0][0])*(P[1][0]-P[0][0])+
+                           (P[1][1]-P[0][1])*(P[1][1]-P[0][1])+
+                           (P[1][2]-P[0][2])*(P[1][2]-P[0][2]));
+    int* aSize = theRenderer->GetRenderWindow()->GetSize();
+    float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1]));
+    vtkDataSet* aDataSet = GetMapper()->GetInput();
+    float aLength = aDataSet->GetLength();
+    float aScale = mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1]));
+    SetScale(aScale);
+  }
+  vtkFollower::Render(theRenderer);
+}
+
+void VTKViewer_UnScaledActor::SetSize(int theSize){
+  mySize = theSize;
+}
+
+//==============================================================================
+
+// The base class for concreate Axis
+// Its only duty is to give correct initialization and destruction
+//   of its pipe-lines
+class VTKViewer_Axis : public vtkObject{
+protected:
+  VTKViewer_Axis();
+  VTKViewer_Axis(const VTKViewer_Axis&);
+  virtual ~VTKViewer_Axis();
+ public:
+  vtkTypeMacro(VTKViewer_Axis,vtkObject);
+  
+  virtual void AddToRender(vtkRenderer* theRenderer){
+    theRenderer->AddActor(myLabelActor);
+    theRenderer->AddActor(myArrowActor);
+    theRenderer->AddActor(myLineActor);
+  }
+
+  virtual void SetVisibility(VTKViewer_Trihedron::TVisibility theVis);
+  virtual VTKViewer_Trihedron::TVisibility GetVisibility() { 
+    return myVisibility;
+  }
+
+  virtual void SetCamera(vtkCamera* theCamera){
+    myLabelActor->SetCamera(theCamera);
+  }
+
+  virtual void SetProperty(vtkProperty* theProperty){
+    myLabelActor->SetProperty(theProperty);
+    myArrowActor->SetProperty(theProperty);
+    myLineActor->SetProperty(theProperty);
+  }
+
+  virtual void SetSize(float theSize);
+
+  virtual VTKViewer_UnScaledActor* GetLabel(){
+    return myLabelActor;
+  }
+
+  virtual VTKViewer_UnScaledActor* GetArrow(){
+    return myArrowActor;
+  }
+
+protected:
+  VTKViewer_Trihedron::TVisibility myVisibility;
+  float myDir[3], myRot[3];
+
+  vtkActor *myLineActor;
+  VTKViewer_UnScaledActor *myArrowActor;
+  VTKViewer_UnScaledActor *myLabelActor;
+
+  vtkPolyDataMapper *myMapper[3];
+  vtkLineSource *myLineSource;
+  vtkConeSource *myConeSource;
+  VTKViewer_VectorText* myVectorText;
+};
+
+VTKViewer_Axis::VTKViewer_Axis(){
+  // Initialize the Line pipe-line representation
+  myLineSource = vtkLineSource::New();
+  myLineSource->SetPoint1(0.0,0.0,0.0);
+
+  myMapper[0] = vtkPolyDataMapper::New();
+  myMapper[0]->SetInput(myLineSource->GetOutput());
+
+  myLineActor = vtkActor::New();
+  myLineActor->SetMapper(myMapper[0]);
+  myLineActor->PickableOff();
+
+  // Initialize the Arrow pipe-line representation
+  myConeSource =  vtkConeSource::New();
+  myConeSource->SetResolution(2);
+  myConeSource->SetAngle(10);
+
+  myMapper[1] = vtkPolyDataMapper::New();
+  myMapper[1]->SetInput(myConeSource->GetOutput());
+  
+  myArrowActor = VTKViewer_UnScaledActor::New();
+  myArrowActor->SetMapper(myMapper[1]);
+  static int aArrowActorSize = 24;
+  myArrowActor->SetSize(aArrowActorSize);
+  myArrowActor->PickableOff();
+
+  // Initialize the Label pipe-line representation
+  myVectorText = VTKViewer_VectorText::New();
+
+  myMapper[2] = vtkPolyDataMapper::New();
+  myMapper[2]->SetInput(myVectorText->GetOutput());
+
+  myLabelActor = VTKViewer_UnScaledActor::New();
+  myLabelActor->SetMapper(myMapper[2]);
+  static int aLabelActorSize = 12;
+  myLabelActor->SetSize(aLabelActorSize);
+  myLabelActor->PickableOff();
+
+  // Initialise visibility param.
+  myVisibility = VTKViewer_Trihedron::eOn;
+}
+
+VTKViewer_Axis::~VTKViewer_Axis(){
+  // Destroy of the Label pipe-line representation
+  myLabelActor->Delete();
+
+  myMapper[2]->RemoveAllInputs();
+  myMapper[2]->Delete();
+
+  myVectorText->Delete();
+
+  // Destroy of the Arrow pipe-line representation
+  myArrowActor->Delete();
+
+  myMapper[1]->RemoveAllInputs();
+  myMapper[1]->Delete();
+
+  myConeSource->Delete();
+
+  // Destroy of the Arrow pipe-line representation
+  myLineActor->Delete();
+
+  myMapper[2]->RemoveAllInputs();
+  myMapper[2]->Delete();
+
+  myLineSource->Delete();
+}
+
+void VTKViewer_Axis::SetVisibility(VTKViewer_Trihedron::TVisibility theVis){
+  switch(theVis){
+  case VTKViewer_Trihedron::eOff:
+  case VTKViewer_Trihedron::eOn:
+    myLabelActor->SetVisibility(theVis);
+    myArrowActor->SetVisibility(theVis);
+    myLineActor->SetVisibility(theVis);
+    break;
+  case VTKViewer_Trihedron::eOnlyLineOn:
+    myLabelActor->VisibilityOff();
+    myArrowActor->VisibilityOff();
+    myLineActor->VisibilityOn();
+    break;
+  default:
+    return;
+  }
+  myVisibility = theVis;
+}
+
+void VTKViewer_Axis::SetSize(float theSize){
+  float aPosition[3] = {myDir[0]*theSize, myDir[1]*theSize, myDir[2]*theSize};
+  myLineSource->SetPoint2(aPosition);
+
+  myArrowActor->SetPosition(0.0,0.0,0.0);
+  myArrowActor->AddPosition(aPosition);
+  myArrowActor->SetOrientation(myRot);
+
+  myLabelActor->SetPosition(0.0,0.0,0.0);
+  myLabelActor->AddPosition(aPosition);
+}
+
+//==============================================================================
+class VTKViewer_XAxis : public VTKViewer_Axis{
+protected:
+  VTKViewer_XAxis();
+  VTKViewer_XAxis(const VTKViewer_XAxis&);
+public:
+  vtkTypeMacro(VTKViewer_XAxis,VTKViewer_Axis);
+  static VTKViewer_XAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_XAxis);
+
+VTKViewer_XAxis::VTKViewer_XAxis(){ 
+  myDir[0] = 1.0; myDir[1] = 0.0; myDir[2] = 0.0;
+  myRot[0] = 0.0; myRot[1] = 0.0; myRot[2] = 0.0;
+  myVectorText->SetText("X");
+  vtkProperty* aProperty = vtkProperty::New();
+  aProperty->SetColor(1.0,0.0,0.0);
+  SetProperty(aProperty);
+  aProperty->Delete();
+}
+
+//==============================================================================
+class VTKViewer_YAxis : public VTKViewer_Axis{
+protected:
+  VTKViewer_YAxis();
+  VTKViewer_YAxis(const VTKViewer_YAxis&);
+public:
+  vtkTypeMacro(VTKViewer_YAxis,VTKViewer_Axis);
+  static VTKViewer_YAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_YAxis);
+
+VTKViewer_YAxis::VTKViewer_YAxis(){ 
+  myDir[0] = 0.0; myDir[1] = 1.0; myDir[2] = 0.0;
+  myRot[0] = 0.0; myRot[1] = 0.0; myRot[2] = 90.;
+  myVectorText->SetText("Y");
+  vtkProperty* aProperty = vtkProperty::New();
+  aProperty->SetColor(0.0,1.0,0.0);
+  SetProperty(aProperty);
+  aProperty->Delete();
+}
+
+//==============================================================================
+class VTKViewer_ZAxis : public VTKViewer_Axis{
+protected:
+  VTKViewer_ZAxis();
+  VTKViewer_ZAxis(const VTKViewer_ZAxis&);
+public:
+  vtkTypeMacro(VTKViewer_ZAxis,VTKViewer_Axis);
+  static VTKViewer_ZAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_ZAxis);
+
+VTKViewer_ZAxis::VTKViewer_ZAxis(){ 
+  myDir[0] = 0.0; myDir[1] = 0.0; myDir[2] = 1.0;
+  myRot[0] = 0.0; myRot[1] = -90; myRot[2] = 0.0;
+  myVectorText->SetText("Z");
+  vtkProperty* aProperty = vtkProperty::New();
+  aProperty->SetColor(0.0,0.0,1.0);
+  SetProperty(aProperty);
+  aProperty->Delete();
+}
+
+//==============================================================================
+
+vtkStandardNewMacro(VTKViewer_Trihedron);
+
+VTKViewer_Trihedron::VTKViewer_Trihedron(){
+  myPresent = vtkActorCollection::New();
+  myAxis[0] = VTKViewer_XAxis::New();
+  myAxis[1] = VTKViewer_YAxis::New();
+  myAxis[2] = VTKViewer_ZAxis::New();
+  static float aSize = 100;
+  SetSize(aSize);
+}
+
+VTKViewer_Trihedron::~VTKViewer_Trihedron(){
+  myPresent->RemoveAllItems();
+  myPresent->Delete();
+  for(int i = 0; i < 3; i++)
+    myAxis[i]->Delete();
+}
+
+void VTKViewer_Trihedron::SetSize(float theSize){
+  mySize = theSize;
+  for(int i = 0; i < 3; i++)
+    myAxis[i]->SetSize(theSize);
+}
+
+void VTKViewer_Trihedron::SetVisibility(TVisibility theVis){
+  for(int i = 0; i < 3; i++)
+    myAxis[i]->SetVisibility(theVis);
+}
+
+VTKViewer_Trihedron::TVisibility VTKViewer_Trihedron::GetVisibility(){
+  return myAxis[0]->GetVisibility();
+}
+
+void VTKViewer_Trihedron::AddToRender(vtkRenderer* theRenderer){
+  vtkCamera* aCamera = theRenderer->GetActiveCamera();
+  for(int i = 0; i < 3; i++){
+    myAxis[i]->AddToRender(theRenderer);
+    myAxis[i]->SetCamera(aCamera);
+  }
+}
+
+void VTKViewer_Trihedron::RemoveFromRender(vtkRenderer* theRenderer){
+  myPresent->InitTraversal();
+  while(vtkActor* anActor = myPresent->GetNextActor())
+    theRenderer->RemoveActor(anActor);
+}
+
+int VTKViewer_Trihedron::GetVisibleActorCount(vtkRenderer* theRenderer){
+  //TVisibility aVis = GetVisibility();
+  //SetVisibility(eOff);
+  vtkActorCollection* aCollection = theRenderer->GetActors();
+  aCollection->InitTraversal();
+  int aCount = 0;
+  while(vtkActor* prop = aCollection->GetNextActor())
+    if( prop->GetVisibility())
+      if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(prop))
+       if(!anActor->IsInfinitive()) 
+         aCount++;
+  //int aCount = theRenderer->VisibleActorCount();
+  //SetVisibility(aVis);
+  return aCount;
+}
+
+void VTKViewer_Trihedron::Render(vtkRenderer* theRenderer){
+  for(int i = 0; i < 3; i++)
+    {
+      myAxis[i]->GetLabel()->Render(theRenderer);
+      myAxis[i]->GetArrow()->Render(theRenderer);
+    }
+}
+
diff --git a/src/VTKViewer/VTKViewer_Trihedron.h b/src/VTKViewer/VTKViewer_Trihedron.h
new file mode 100644 (file)
index 0000000..056ea15
--- /dev/null
@@ -0,0 +1,69 @@
+//  SALOME VTKViewer : 
+//
+//  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_Trihedron.h
+//  Author : Alexey PETROV
+//  Module : SALOME
+//  $Header: 
+
+#ifndef VTKViewer_Trihedron_H
+#define VTKViewer_Trihedron_H
+
+#include <vtkObject.h>
+
+class vtkActorCollection;
+class VTKViewer_Axis;
+class vtkRenderer;
+
+class VTKViewer_Trihedron : public vtkObject{
+ protected:
+  VTKViewer_Trihedron();
+  VTKViewer_Trihedron(const VTKViewer_Trihedron&);
+  virtual ~VTKViewer_Trihedron();
+ public:
+  vtkTypeMacro(VTKViewer_Trihedron,vtkObject);
+  static VTKViewer_Trihedron *New();
+  
+  virtual void SetSize(float theSize);
+  virtual float GetSize() { return mySize;}
+
+  enum TVisibility{eOff, eOn, eOnlyLineOn};
+  virtual void SetVisibility(TVisibility theVis);
+  virtual void VisibilityOff() { SetVisibility(eOff);}
+  virtual void VisibilityOn() { SetVisibility(eOn);}
+  virtual TVisibility GetVisibility();
+
+  virtual void AddToRender(vtkRenderer* theRenderer);
+  virtual void RemoveFromRender(vtkRenderer* theRenderer);
+
+  virtual int GetVisibleActorCount(vtkRenderer* theRenderer);
+  
+  virtual void  Render(vtkRenderer *theRenderer);
+  
+protected:
+  vtkActorCollection* myPresent;
+  VTKViewer_Axis* myAxis[3];
+  float mySize;
+};
+
+#endif
diff --git a/src/VTKViewer/VTKViewer_Utilities.cxx b/src/VTKViewer/VTKViewer_Utilities.cxx
new file mode 100644 (file)
index 0000000..ce64a1e
--- /dev/null
@@ -0,0 +1,195 @@
+//  SALOME VTKViewer : 
+//
+//  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_Utilities.cxx
+//  Author : Alexey PETROV
+//  Module : SALOME
+//  $Header: 
+
+#include "VTKViewer_Utilities.h"
+#include "utilities.h"
+#include "SALOME_Actor.h"
+
+// VTK Includes
+#include <vtkMath.h>
+#include <vtkCamera.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+
+using namespace std;
+
+//see vtkRenderer::ResetCamera(float bounds[6]) method
+void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint){  
+  if(!theRenderer) return;
+  float bounds[6];
+  int aCount = ComputeVisiblePropBounds(theRenderer,bounds);
+  if(theUsingZeroFocalPoint || aCount){
+    float aLength = bounds[1]-bounds[0];
+    aLength = max((bounds[3]-bounds[2]),aLength);
+    aLength = max((bounds[5]-bounds[4]),aLength);
+    
+    double vn[3];
+    if ( theRenderer->GetActiveCamera() != NULL )
+      theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
+    else{
+      INFOS("Trying to reset non-existant camera");
+      return;
+    }
+    
+    float center[3] = {0.0, 0.0, 0.0};
+    if(!theUsingZeroFocalPoint){
+      center[0] = (bounds[0] + bounds[1])/2.0;
+      center[1] = (bounds[2] + bounds[3])/2.0;
+      center[2] = (bounds[4] + bounds[5])/2.0;
+    }
+    theRenderer->GetActiveCamera()->SetFocalPoint(center[0],center[1],center[2]);
+    
+    float width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
+                      (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
+                      (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
+    
+    double ang = theRenderer->GetActiveCamera()->GetViewAngle();
+    float distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
+    
+    // check view-up vector against view plane normal
+    double *vup = theRenderer->GetActiveCamera()->GetViewUp();
+    if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 ){
+      MESSAGE("Resetting view-up since view plane normal is parallel");
+      theRenderer->GetActiveCamera()->SetViewUp(-vup[2], vup[0], vup[1]);
+    }
+    
+    // update the camera
+    theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
+                                               center[1]+distance*vn[1],
+                                               center[2]+distance*vn[2]);
+    // find size of the window
+    int* winsize = theRenderer->GetSize();
+    if(winsize[0] < winsize[1]) width *= float(winsize[1])/float(winsize[0]);
+    
+    if(theUsingZeroFocalPoint) width *= sqrt(2.0);
+    
+    theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
+  }
+  //workaround on VTK
+  //theRenderer->ResetCameraClippingRange(bounds);
+  ResetCameraClippingRange(theRenderer);
+}
+
+
+// Compute the bounds of the visible props
+int ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]){
+  vtkProp    *prop;
+  float      *bounds;
+  int        aCount=0;
+
+  theBounds[0] = theBounds[2] = theBounds[4] = VTK_LARGE_FLOAT;
+  theBounds[1] = theBounds[3] = theBounds[5] = -VTK_LARGE_FLOAT;
+  
+  // loop through all props
+  vtkActorCollection* aCollection = theRenderer->GetActors();
+  aCollection->InitTraversal();
+  while (vtkActor* prop = aCollection->GetNextActor()) {
+    // if it's invisible, or has no geometry, we can skip the rest 
+    if ( prop->GetVisibility() )
+      {
+      if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(prop))
+       if(anActor->IsInfinitive()) continue;
+      bounds = prop->GetBounds();
+      // make sure we haven't got bogus bounds
+      if ( bounds != NULL &&
+           bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
+           bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
+           bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT )
+        {
+        aCount++;
+
+        if (bounds[0] < theBounds[0])
+          {
+          theBounds[0] = bounds[0]; 
+          }
+        if (bounds[1] > theBounds[1])
+          {
+          theBounds[1] = bounds[1]; 
+          }
+        if (bounds[2] < theBounds[2])
+          {
+          theBounds[2] = bounds[2]; 
+          }
+        if (bounds[3] > theBounds[3])
+          {
+          theBounds[3] = bounds[3]; 
+          }
+        if (bounds[4] < theBounds[4])
+          {
+          theBounds[4] = bounds[4]; 
+          }
+        if (bounds[5] > theBounds[5])
+          {
+          theBounds[5] = bounds[5]; 
+          }
+        }//not bogus
+      }
+    }
+  return aCount;
+}
+
+
+//see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
+void ResetCameraClippingRange(vtkRenderer* theRenderer){
+  if(!theRenderer || !theRenderer->VisibleActorCount()) return;
+
+  vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
+  if( anActiveCamera == NULL ){
+    MESSAGE("Trying to reset clipping range of non-existant camera");
+    return;
+  }
+  
+  // Find the plane equation for the camera view plane
+  double vn[3];
+  anActiveCamera->GetViewPlaneNormal(vn);
+  double  position[3];
+  anActiveCamera->GetPosition(position);
+
+  float bounds[6];
+  theRenderer->ComputeVisiblePropBounds(bounds);
+
+  double center[3];
+  center[0] = (bounds[0] + bounds[1])/2.0;
+  center[1] = (bounds[2] + bounds[3])/2.0;
+  center[2] = (bounds[4] + bounds[5])/2.0;
+  
+  double width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
+                    (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
+                    (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
+
+  double distance = sqrt((position[0]-center[0])*(position[0]-center[0]) +
+                        (position[1]-center[1])*(position[1]-center[1]) +
+                        (position[2]-center[2])*(position[2]-center[2]));
+
+  float range[2] = {distance - width/2.0, distance + width/2.0};
+
+  // Do not let the range behind the camera throw off the calculation.
+  if (range[0] < 0.0) range[0] = 0.0;
+
+  anActiveCamera->SetClippingRange( range );
+}
diff --git a/src/VTKViewer/VTKViewer_Utilities.h b/src/VTKViewer/VTKViewer_Utilities.h
new file mode 100644 (file)
index 0000000..e297ce7
--- /dev/null
@@ -0,0 +1,39 @@
+//  SALOME VTKViewer : 
+//
+//  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_Utilities.h
+//  Author : Alexey PETROV
+//  Module : SALOME
+//  $Header: 
+
+#ifndef VTKViewer_Utilities_H
+#define VTKViewer_Utilities_H
+
+class vtkRenderer;
+
+extern void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint = false);
+extern int ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]);
+extern void ResetCameraClippingRange(vtkRenderer* theRenderer);
+extern float EPS_BNDBOX;
+
+#endif
index b54107cd51a135e34e560f9f8579df89af503a09..8f9e8e286b1f39d0388a8f6c3a64b3c39fc8bf18 100644 (file)
 //  $Header$
 
 #include "VTKViewer_ViewFrame.h"
+#include "VTKViewer_Utilities.h"
+#include "VTKViewer_Trihedron.h"
 #include "VTKViewer_RenderWindow.h"
+#include "VTKViewer_InteractorStyleSALOME.h"
 
 #include "SALOME_Transform.h"
 #include "SALOME_TransformFilter.h"
@@ -40,8 +43,6 @@
 #include "QAD_Desktop.h"
 #include "SALOME_Selection.h"
 #include "SALOME_InteractiveObject.hxx"
-#include "VTKViewer_InteractorStyleSALOME.h"
-#include "VTKViewer_VectorText.h"
 
 #include "utilities.h"
 
 // VTK Includes
 #include <vtkActor.h>
 #include <vtkRenderer.h>
-#include <vtkPolyDataMapper.h> 
-
-#include <vtkMath.h>
-#include <vtkLine.h>
-#include <vtkConeSource.h>
-#include <vtkFollower.h>
+#include <vtkTransform.h>
 
 using namespace std;
+
 /*!
     Constructor
 */
@@ -70,186 +67,16 @@ VTKViewer_ViewFrame::VTKViewer_ViewFrame(QWidget* parent, const char* name)
 {
   m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1;
   m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1;
+  m_Triedron = VTKViewer_Trihedron::New();
   m_Transform = SALOME_Transform::New();
+  //m_Renderer = VTKViewer_Renderer::New() ;
+  m_Renderer = vtkRenderer::New() ;
 
-  //  m_InitialSetupDone = false ;
+  m_Triedron->AddToRender(m_Renderer);
   InitialSetup();
-}
-
-
-vtkFollower* CreateTextActor(char *text, float aSize) {
-  VTKViewer_VectorText* aTxt = VTKViewer_VectorText::New();
-  aTxt->SetText(text);
-  vtkPolyDataMapper* textMapper = vtkPolyDataMapper::New();
-  textMapper->SetInput(aTxt->GetOutput());
-  vtkFollower* textActor = vtkFollower::New();
-  textActor->SetMapper(textMapper);
-  float aScale = 17 * aSize/100;
-  textActor->SetScale(aScale, aScale, aScale);
-  return textActor;
-}
-
-void VTKViewer_ViewFrame::AddVector(float* o,float* p,vtkRenderer* renderer, float aSize) {
-  vtkPoints* myPoints = vtkPoints::New();
-  vtkLine* myLine = vtkLine::New();
-
-  myPoints->InsertNextPoint(o);
-  myPoints->InsertNextPoint(p);
-
-  (myLine->GetPointIds())->InsertNextId(0);
-  (myLine->GetPointIds())->InsertNextId(1);
-
-  vtkActor* lineActor = vtkActor::New();
-
-  vtkCellArray* cell = vtkCellArray::New();
-
-  cell->InsertNextCell(myLine);
-
-  vtkPolyData* output = vtkPolyData::New();
-  
-  output->SetPoints(myPoints);
-  output->SetLines(cell);
-  vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
-
-  mapper->SetInput(output);
-
-  lineActor->SetMapper(mapper);
-
-  // Create CONE
-
-  vtkConeSource* acone =  vtkConeSource::New();
-
-  float dim = aSize;
-
-  acone->SetResolution(2);
-  //  acone->SetAngle(70);
-  acone->SetRadius(0.02*dim);
-  acone->SetHeight(0.08*dim);
-
-  vtkActor* coneActor = vtkActor::New();
-  vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
-  coneMapper->SetInput(acone->GetOutput());
-
-  coneActor->SetMapper(coneMapper);
-  float rot[3];
-  rot[0]=0; rot[1]=0; rot[2]=0;
-
-  vtkFollower* aTextActor;
-
-  coneActor->AddPosition(p);
-  if(p[0]!=0) {
-    // x
-    aTextActor = CreateTextActor("X", dim);
-  } else if(p[1]!=0) {
-    // y
-    rot[2]=90;
-    coneActor->AddOrientation(rot);
-    aTextActor = CreateTextActor("Y", dim);
-  } else if(p[2]!=0) {
-    // z
-    rot[1]=-90;
-    coneActor->AddOrientation(rot);
-    aTextActor = CreateTextActor("Z", dim);
-  }
-  aTextActor->AddPosition(p);
-  aTextActor->SetCamera(renderer->GetActiveCamera());
-
-  coneActor->GetProperty()->SetInterpolation(1);
-  coneActor->GetProperty()->SetRepresentationToSurface();
-  coneActor->GetProperty()->SetAmbient(1);
-  coneActor->GetProperty()->SetAmbientColor(1,1,1);
-  coneActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
-  coneActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
-  lineActor->GetProperty()->SetInterpolation(1);
-  lineActor->GetProperty()->SetRepresentationToSurface();
-  lineActor->GetProperty()->SetAmbient(1);
-  lineActor->GetProperty()->SetAmbientColor(1,1,1);
-  lineActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
-  lineActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
-  aTextActor->GetProperty()->SetAmbient(1);
-  aTextActor->GetProperty()->SetAmbientColor(1,1,1);
-  aTextActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
-  aTextActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-     
-  coneActor->PickableOff();
-  lineActor->PickableOff();
-  aTextActor->PickableOff();
-  
-  m_Triedron->AddItem(coneActor);
-  m_Triedron->AddItem(lineActor);
-  m_Triedron->AddItem(aTextActor);
-
-  renderer->AddActor(coneActor);
-  renderer->AddActor(lineActor);
-  renderer->AddActor(aTextActor);
 }  
 
-bool VTKViewer_ViewFrame::isTrihedronDisplayed() {
-  m_Triedron->InitTraversal();
-  vtkActor *ac = m_Triedron->GetNextActor();
-  while(!(ac==NULL)) {
-    if(ac->GetVisibility()) return true;
-    ac = m_Triedron->GetNextActor();
-  }
-  return false;
-}
-
-void VTKViewer_ViewFrame::SetTrihedronSize(int size)
-{
-  m_Triedron->InitTraversal();
-  vtkActor* anActor = m_Triedron->GetNextActor();
-  while(!(anActor==NULL)) {  
-    m_Renderer->RemoveActor( anActor );
-    anActor = m_Triedron->GetNextActor();
-  }
-
-  m_Triedron->RemoveAllItems();
-  AddAxis(m_Renderer);
-  m_RW->update();
-}
-
-
-void VTKViewer_ViewFrame::AddAxis(vtkRenderer* renderer) {  
-  float origine[3];
-  float X[3];
-  float Y[3];
-  float Z[3];
-  float dim;
-
-  QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
-  if( Size.isEmpty() ){
-    dim = 100;
-  } else {
-    dim = Size.toFloat();
-  }
-
-  origine[0]=0;        origine[1]=0;        origine[2]=0;
-  X[0]=origine[0]+dim; X[1]=origine[0];     X[2]=origine[0];
-  Y[0]=origine[0];     Y[1]=origine[0]+dim; Y[2]=origine[0];
-  Z[0]=origine[0];     Z[1]=origine[0];     Z[2]=origine[0]+dim;
-
-  AddVector(origine,X,renderer, dim);
-  AddVector(origine,Y,renderer, dim);
-  AddVector(origine,Z,renderer, dim);
-}
-
-/*!
-  Returns widget containing 3D-Viewer
-*/
-QWidget* VTKViewer_ViewFrame::getViewWidget() 
-{
-  return m_RW;
-}
-
-
 void VTKViewer_ViewFrame::InitialSetup() {
-  m_Renderer = vtkRenderer::New() ;
-
   m_RW = new VTKViewer_RenderWindow(this, "RenderWindow");
   m_RW->getRenderWindow()->AddRenderer(m_Renderer);
 
@@ -266,11 +93,7 @@ void VTKViewer_ViewFrame::InitialSetup() {
     m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
   else
     m_Renderer->SetBackground( 0, 0, 0 );
-  // CREATE AXIS
-  m_Triedron = vtkActorCollection::New();
-  AddAxis(m_Renderer);
+  
   // Create an interactor.
   m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
   m_RWInteractor->setGUIWindow(m_RW);
@@ -281,7 +104,7 @@ void VTKViewer_ViewFrame::InitialSetup() {
   m_RWInteractor->SetInteractorStyle(RWS); 
 
   m_RWInteractor->Initialize();
-  RWS->setTriedron( m_Triedron );
+  RWS->setTriedron(m_Triedron);
   //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle 
   RWS->FindPokedRenderer(0, 0);
 
@@ -290,414 +113,218 @@ void VTKViewer_ViewFrame::InitialSetup() {
 }
 
 VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
-  //
+  m_Transform->Delete() ;
   // In order to ensure that the interactor unregisters
   // this RenderWindow, we assign a NULL RenderWindow to 
   // it before deleting it.
-  //
-  m_Transform->Delete() ;
-    
   m_RWInteractor->SetRenderWindow(NULL) ;
   m_RWInteractor->Delete() ;
   
   //m_RW->Delete() ;
-
+  m_Renderer->RemoveAllProps();
   // NRI : BugID 1137:  m_Renderer->Delete() ;
+  m_Triedron->Delete();
+  MESSAGE("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()");
 }
 
+/*!
+  Returns widget containing 3D-Viewer
+*/
+QWidget* VTKViewer_ViewFrame::getViewWidget(){
+  return m_RW;
+}
+
+bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
+  return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+}
+
+void VTKViewer_ViewFrame::onAdjustTrihedron(){   
+  if(!isTrihedronDisplayed()) 
+    return;
+  int aVisibleNum = m_Triedron->GetVisibleActorCount(m_Renderer);
+  if(aVisibleNum){
+    // calculating diagonal of visible props of the renderer
+    float bnd[6];
+    m_Triedron->VisibilityOff();
+    ::ComputeVisiblePropBounds(m_Renderer,bnd);
+    m_Triedron->VisibilityOn();
+    float aLength = 0;
+    static bool CalcByDiag = false;
+    if(CalcByDiag){
+      aLength = sqrt((bnd[1]-bnd[0])*(bnd[1]-bnd[0])+
+                    (bnd[3]-bnd[2])*(bnd[3]-bnd[2])+
+                    (bnd[5]-bnd[4])*(bnd[5]-bnd[4]));
+    }else{
+      aLength = bnd[1]-bnd[0];
+      aLength = max((bnd[3]-bnd[2]),aLength);
+      aLength = max((bnd[5]-bnd[4]),aLength);
+    }
+   
+    static float aSizeInPercents = 105;
+    QString aSetting = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
+    if(!aSetting.isEmpty()) aSizeInPercents = aSetting.toFloat();
+
+    static float EPS_SIZE = 5.0E-3;
+    float aSize = m_Triedron->GetSize();
+    float aNewSize = aLength*aSizeInPercents/100.0;
+    // if the new trihedron size have sufficient difference, then apply the value
+    if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE)
+      m_Triedron->SetSize(aNewSize);
+  }
+  m_Triedron->Render(m_Renderer);
+  ::ResetCameraClippingRange(m_Renderer);
+}
 
 /*!
   Display/hide Trihedron
 */
-void VTKViewer_ViewFrame::onViewTrihedron()
-{
-  if (isTrihedronDisplayed()) {
-    m_Triedron->InitTraversal();
-    vtkActor *ac = m_Triedron->GetNextActor();
-    while(!(ac==NULL)) {
-      ac->VisibilityOff();
-      ac = m_Triedron->GetNextActor();
-    }
+void VTKViewer_ViewFrame::onViewTrihedron(){
+  if(!m_Triedron) return;
+  if(isTrihedronDisplayed())
+    m_Triedron->VisibilityOff();
+  else{
+    m_Triedron->VisibilityOn();
   }
-  else {
-    m_Triedron->InitTraversal();
-    vtkActor *ac = m_Triedron->GetNextActor();
-    while(!(ac==NULL)) {
-      ac->VisibilityOn();
-      ac = m_Triedron->GetNextActor();
-    }
-    m_TriedronVisible = true;
-  }  
-  m_RW->update();
+  Repaint();
 }
 
 /*!
   Provides top projection of the active view
 */
-void VTKViewer_ViewFrame::onViewTop() {
+void VTKViewer_ViewFrame::onViewTop(){
   vtkCamera* camera = m_Renderer->GetActiveCamera();
-  camera->SetFocalPoint(0,0,0);
   camera->SetPosition(0,0,1);
   camera->SetViewUp(0,1,0);
-  m_Renderer->ResetCamera();  
+  camera->SetFocalPoint(0,0,0);
   onViewFitAll();
-  m_RW->update();
 }
 
 /*!
   Provides bottom projection of the active view
 */
-void VTKViewer_ViewFrame::onViewBottom()
-{
+void VTKViewer_ViewFrame::onViewBottom(){
   vtkCamera* camera = m_Renderer->GetActiveCamera();
-  camera->SetFocalPoint(0,0,0);
   camera->SetPosition(0,0,-1);
   camera->SetViewUp(0,1,0);
-  m_Renderer->ResetCamera();  
+  camera->SetFocalPoint(0,0,0);
   onViewFitAll();
-  m_RW->update();
 }
 
 /*!
   Provides left projection of the active view
 */
-void VTKViewer_ViewFrame::onViewLeft()    
-{
+void VTKViewer_ViewFrame::onViewLeft(){
   vtkCamera* camera = m_Renderer->GetActiveCamera(); 
-  camera->SetFocalPoint(0,0,0);
   camera->SetPosition(0,1,0);
   camera->SetViewUp(0,0,1);
-  m_Renderer->ResetCamera();  
+  camera->SetFocalPoint(0,0,0);
   onViewFitAll();
-  m_RW->update(); 
 }
 
 /*!
   Provides right projection of the active view
 */
-void VTKViewer_ViewFrame::onViewRight()
-{
+void VTKViewer_ViewFrame::onViewRight(){
   vtkCamera* camera = m_Renderer->GetActiveCamera();
-  camera->SetFocalPoint(0,0,0);
   camera->SetPosition(0,-1,0);
   camera->SetViewUp(0,0,1);
-  m_Renderer->ResetCamera();  
+  camera->SetFocalPoint(0,0,0);
   onViewFitAll();
-  m_RW->update();
 }
 
 /*!
   Provides back projection of the active view
 */
-void VTKViewer_ViewFrame::onViewBack()
-{
+void VTKViewer_ViewFrame::onViewBack(){
   vtkCamera* camera = m_Renderer->GetActiveCamera();
   camera->SetPosition(-1,0,0);
-  camera->SetFocalPoint(0,0,0);
   camera->SetViewUp(0,0,1);
-  m_Renderer->ResetCamera();  
+  camera->SetFocalPoint(0,0,0);
   onViewFitAll();
-  m_RW->update();
 }
 
 /*!
   Provides front projection of the active view
 */
-void VTKViewer_ViewFrame::onViewFront()
-{
+void VTKViewer_ViewFrame::onViewFront(){
   vtkCamera* camera = m_Renderer->GetActiveCamera();
   camera->SetPosition(1,0,0);
-  camera->SetFocalPoint(0,0,0);
   camera->SetViewUp(0,0,1);
-  m_Renderer->ResetCamera();  
+  camera->SetFocalPoint(0,0,0);
   onViewFitAll();
-  m_RW->update();
 }
 
 /*!
-  Reset the active view
+  Fits all objects in the active view
 */
-void VTKViewer_ViewFrame::onViewReset()    
-{
-  vtkCamera* camera = m_Renderer->GetActiveCamera();
-  camera->SetPosition(1,-1,1);
-  camera->SetFocalPoint(0,0,0);
-  camera->SetViewUp(0,0,1);
-  m_Renderer->ResetCamera();  
-  
-  double aOldScale = camera->GetParallelScale();
-  camera->SetParallelScale(500);
-  double aNewScale = camera->GetParallelScale();
-  
-  //for controlling labels scale after reset
-  float dim;
-  QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
-  if( Size.isEmpty() ){
-    dim = 100;
-  } else {
-    dim = Size.toFloat();
-  }
-  float aScale = 17 * dim/100;
+void VTKViewer_ViewFrame::onViewFitAll(){
+  m_RWInteractor->GetInteractorStyleSALOME()->ViewFitAll();
+//   int aTriedronWasVisible = isTrihedronDisplayed();
+//   if(m_Triedron->GetVisibleActorCount(m_Renderer)){
+//     m_Triedron->VisibilityOff();
+//     ::ResetCamera(m_Renderer);
+//   }else{
+//     m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+//     ::ResetCamera(m_Renderer,true);
+//   }
+//   if(aTriedronWasVisible) m_Triedron->VisibilityOn();
+//   else m_Triedron->VisibilityOff();
 
-  m_Triedron->InitTraversal();
-  vtkActor *ac = m_Triedron->GetNextActor();
-  bool IsConeActor = true;
-  while(!(ac==NULL)) {
-    if(ac->IsA("vtkFollower")) {
-      ac->SetScale(aScale, aScale, aScale);
-      IsConeActor = true;
-    }
-    else {
-      if (IsConeActor) {
-       //coneActor is the first in the list (see m_Triedron->AddItem(...) in VTKViewer_ViewFrame::AddVector(...))
-       IsConeActor = false;
-      } 
-    }
-    ac = m_Triedron->GetNextActor();
-  }
+  Repaint();
+}
 
-  m_Renderer->ResetCameraClippingRange();
-  m_RW->update();
+/*!
+  Reset the active view
+*/
+void VTKViewer_ViewFrame::onViewReset(){
+  int aTriedronIsVisible = isTrihedronDisplayed();
+  m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+  ::ResetCamera(m_Renderer,true);  
+  vtkCamera* aCamera = m_Renderer->GetActiveCamera();
+  aCamera->SetPosition(1,-1,1);
+  aCamera->SetViewUp(0,0,1);
+  ::ResetCamera(m_Renderer,true);  
+  if(aTriedronIsVisible) m_Triedron->VisibilityOn();
+  else m_Triedron->VisibilityOff();
+  static float aCoeff = 3.0;
+  aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
+  Repaint();
 }
 
 /*!
   Rotates the active view
 */
-void VTKViewer_ViewFrame::onViewRotate()
-{
-  VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
-  if (RWS)
-    RWS->startRotate();
+void VTKViewer_ViewFrame::onViewRotate(){
+  m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
 }
 
 /*!
   Sets a new center of the active view
 */
-void VTKViewer_ViewFrame::onViewGlobalPan()
-{
-  VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
-  if (RWS)
-    RWS->startGlobalPan();
+void VTKViewer_ViewFrame::onViewGlobalPan(){
+  if(m_Triedron->GetVisibleActorCount(m_Renderer))
+    m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
 }
 
 /*!
   Zooms the active view
 */
-void VTKViewer_ViewFrame::onViewZoom()
-{
-  VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
-  if (RWS)
-    RWS->startZoom();
+void VTKViewer_ViewFrame::onViewZoom(){
+  m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
 }
 
 /*!
   Moves the active view
 */
-void VTKViewer_ViewFrame::onViewPan()
-{
-  VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
-  if (RWS)
-    RWS->startPan();
+void VTKViewer_ViewFrame::onViewPan(){
+  m_RWInteractor->GetInteractorStyleSALOME()->startPan();
 }
 
 /*!
   Fits all obejcts within a rectangular area of the active view
 */
-void VTKViewer_ViewFrame::onViewFitArea()
-{
-  VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
-  if (RWS)
-    RWS->startFitArea();
-}
-
-/*!
-  Fits all objects in the active view
-*/
-// Reset the camera clipping range to include this entire bounding box
-static void ResetCameraClippingRange(vtkRenderer* theRenderer, float bounds[6] )
-{
-  //see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
-  double  vn[3], position[3], a, b, c, d;
-  double  range[2], dist;
-  int     i, j, k;
-  float center[3];
-  float distance;
-  float width;
-
-  vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
-  if ( anActiveCamera == NULL )
-    {
-      //vtkErrorMacro(<< "Trying to reset clipping range of non-existant camera");
-    return;
-    }
-  
-  // Find the plane equation for the camera view plane
-  anActiveCamera->GetViewPlaneNormal(vn);
-  anActiveCamera->GetPosition(position);
-//  a = -vn[0];
-//  b = -vn[1];
-//  c = -vn[2];
-//  d = -(a*position[0] + b*position[1] + c*position[2]);
-
-  // Set the max near clipping plane and the min far clipping plane
-//  range[0] = a*bounds[0] + b*bounds[2] + c*bounds[4] + d;
-//  range[1] = 1e-18;
-
-  // Find the closest / farthest bounding box vertex
-//  for ( k = 0; k < 2; k++ )
-//    {
-//    for ( j = 0; j < 2; j++ )
-//       {
-//       for ( i = 0; i < 2; i++ )
-//         {
-//         dist = a*bounds[i] + b*bounds[2+j] + c*bounds[4+k] + d;
-//         range[0] = (dist<range[0])?(dist):(range[0]);
-//         range[1] = (dist>range[1])?(dist):(range[1]);
-//         }
-//       }
-//    }
-  
-  center[0] = (bounds[0] + bounds[1])/2.0;
-  center[1] = (bounds[2] + bounds[3])/2.0;
-  center[2] = (bounds[4] + bounds[5])/2.0;
-  width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
-              (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
-              (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
-  distance = sqrt((position[0]-center[0])*(position[0]-center[0]) +
-                 (position[1]-center[1])*(position[1]-center[1]) +
-                 (position[2]-center[2])*(position[2]-center[2]));
-  range[0] = distance - width/2.0;
-  range[1] = distance + width/2.0;
-
-  // Give ourselves a little breathing room
-  range[0] = 0.99*range[0] - (range[1] - range[0])*0.5;
-  range[1] = 1.01*range[1] + (range[1] - range[0])*0.5;
-
-  // Make sure near is not bigger than far
-  range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
-
-  // Make sure near is at least some fraction of far - this prevents near
-  // from being behind the camera or too close in front. How close is too
-  // close depends on the resolution of the depth buffer
-  int ZBufferDepth = 16;
-  vtkRenderWindow* aRenderWindow = theRenderer->GetRenderWindow();
-  if (aRenderWindow)
-    {
-      ZBufferDepth = aRenderWindow->GetDepthBufferSize();
-    }
-  //
-  if ( ZBufferDepth <= 16 )
-    {
-    range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
-    }
-  else if ( ZBufferDepth <= 24 )
-    {
-    range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
-    }
-  else
-    {
-    range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
-    }
-  anActiveCamera->SetClippingRange( range );
-}
-
-static void ResetCamera(vtkRenderer* theRenderer, vtkActorCollection* theTriedron, VTKViewer_RenderWindowInteractor* theRWInteractor){  
-  //see vtkRenderer::ResetCamera(float bounds[6]) method
-  float      bounds[6];
-  if(!theRenderer) return;
-  theRenderer->ComputeVisiblePropBounds( bounds );
-
-  float center[3];
-  float distance;
-  float width;
-  double vn[3], *vup;
-  int* winsize;
-  
-  if ( theRenderer->GetActiveCamera() != NULL )
-    {
-    theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
-    }
-  else
-    {
-    MESSAGE("Trying to reset non-existant camera");
-    return;
-    }
-
-  center[0] = (bounds[0] + bounds[1])/2.0;
-  center[1] = (bounds[2] + bounds[3])/2.0;
-  center[2] = (bounds[4] + bounds[5])/2.0;
-  width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
-              (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
-              (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
-  double ang = theRenderer->GetActiveCamera()->GetViewAngle();
-  distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
-  
-  // find size of the window
-  winsize = theRenderer->GetSize();
-  
-  // check view-up vector against view plane normal
-  vup = theRenderer->GetActiveCamera()->GetViewUp();
-  if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 )
-    {
-    MESSAGE("Resetting view-up since view plane normal is parallel");
-    theRenderer->GetActiveCamera()->SetViewUp(-vup[2], vup[0], vup[1]);
-    }
-
-  // update the camera
-  theRenderer->GetActiveCamera()->SetFocalPoint(center[0],center[1],center[2]);
-  theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
-                                  center[1]+distance*vn[1],
-                                  center[2]+distance*vn[2]);
-  // setup default parallel scale
-  double aOldScale = theRenderer->GetActiveCamera()->GetParallelScale();
-  
-  if(winsize[0]<winsize[1] )
-    width=width*(float(winsize[1])/float(winsize[0]));
-  
-  theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
-  double aNewScale = theRenderer->GetActiveCamera()->GetParallelScale();
-  
-  // for controlling label size 
-  VTKViewer_InteractorStyleSALOME* Style = 0;
-  if (theRWInteractor->GetInteractorStyle()->IsA("VTKViewer_InteractorStyleSALOME")) {
-    Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(theRWInteractor->GetInteractorStyle());
-    Style->ControlLblSize(aOldScale,aNewScale);
-  }
-  //workaround on VTK
-  //theRenderer->ResetCameraClippingRange(bounds);
-  ResetCameraClippingRange(theRenderer,bounds);
-}
-
-void VTKViewer_ViewFrame::onViewFitAll()
-{
-  Standard_Boolean TriedronWasVisible = false;
-  if (isTrihedronDisplayed()) {
-    m_Triedron->InitTraversal();
-    vtkActor *ac = m_Triedron->GetNextActor();
-    while(!(ac==NULL)) {
-      ac->VisibilityOff();
-      ac = m_Triedron->GetNextActor();
-    }
-    TriedronWasVisible = true;
-  }
-  bool hasVisibleActors = m_Renderer->VisibleActorCount() > 0;
-  if ( hasVisibleActors ) {   // if there are visible actors, not to take into account Trihedron
-    ResetCamera(m_Renderer,m_Triedron,m_RWInteractor);
-  } 
-  if(TriedronWasVisible) {
-    m_Triedron->InitTraversal();
-    vtkActor *ac = m_Triedron->GetNextActor();
-    while(!(ac==NULL)) {
-      ac->VisibilityOn();
-      ac = m_Triedron->GetNextActor();
-    }
-    if ( !hasVisibleActors ) { // if there are NO visible actors, fit view to see only Trihedron
-      ResetCamera(m_Renderer,m_Triedron,m_RWInteractor);
-    } 
-  }
-  //m_Renderer->ResetCameraClippingRange();
-  m_RW->update();
+void VTKViewer_ViewFrame::onViewFitArea(){
+  m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
 }
 
 /*!
@@ -967,9 +594,9 @@ void VTKViewer_ViewFrame::EraseAll()
 }
 
 
-void VTKViewer_ViewFrame::Repaint()
+void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
 {
-  // m_RWInteractor->Render();
+  if (theUpdateTrihedron) onAdjustTrihedron();
   m_RW->update();
 }
 
@@ -979,12 +606,7 @@ void VTKViewer_ViewFrame::GetScale(double theScale[3]){
 
 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
   m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
-  m_Transform->Modified();
-  vtkActorCollection* theActors = m_Renderer->GetActors();
-  theActors->InitTraversal();
-  vtkActor *anActor;
-  while(anActor = theActors->GetNextActor())
-    anActor->GetMapper()->Update();
+  m_RWInteractor->Render();
   Repaint();
 }
 
@@ -992,18 +614,12 @@ void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool update /*=false
   theActor->SetVisibility(true);
   theActor->AddToRender(m_Renderer);
   theActor->SetTransform(m_Transform);
-  if(update){
-    m_Renderer->ResetCameraClippingRange();
-    m_RWInteractor->Render();
-  }
+  if(update) Repaint();
 }
 
 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool update /*=false*/ ){
   theActor->RemoveFromRender(m_Renderer);
-  if(update){
-    m_Renderer->ResetCameraClippingRange();
-    m_RWInteractor->Render();
-  }
+  if(update) Repaint();
 }
 
 
index 64467faa64a600607bf222e67111cc996a9463ab..83fc35ab1feb680b404e48efa4dded7804bfc75c 100644 (file)
@@ -37,8 +37,8 @@
 
 // VTK Includes
 class vtkRenderer;
-class vtkActorCollection;
 class vtkTransform;
+class VTKViewer_Trihedron;
 
 class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{
   Q_OBJECT;
@@ -54,8 +54,7 @@ class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{
   VTKViewer_RenderWindowInteractor* getRWInteractor() {return m_RWInteractor;}
 
   bool                           isTrihedronDisplayed();
-  void                           SetTrihedronSize( int dim );
-
   void                           setBackgroundColor( const QColor& );
   QColor                         backgroundColor() const;
   
@@ -89,7 +88,8 @@ class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{
   void           Erase(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly = true);
   void           DisplayAll();
   void           EraseAll();
-  void           Repaint();
+  void           Repaint(bool theUpdateTrihedron);
+  void           Repaint() { Repaint(true); }
 
   //apply existing transformation on adding SALOME_Actor
   void SetScale(double theScale[3]);
@@ -97,10 +97,6 @@ class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{
   void AddActor(SALOME_Actor*, bool update = false);
   void RemoveActor(SALOME_Actor*, bool update = false);
 
- private:
-  void AddVector(float* o,float* p,vtkRenderer* renderer, float aSize);
-  void AddAxis(vtkRenderer* renderer);
  public slots:
   void           onViewPan(); 
   void           onViewZoom();
@@ -116,20 +112,19 @@ class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{
   void           onViewBottom();
   void           onViewTop();
   void           onViewTrihedron(); 
+  void           onAdjustTrihedron();
  
  private:
   double                        m_ViewUp[3];
   double                        m_ViewNormal[3];
-
+  
   void                          InitialSetup();
 
   vtkRenderer*                      m_Renderer;
   VTKViewer_RenderWindow*           m_RW;
   VTKViewer_RenderWindowInteractor* m_RWInteractor;
 
-  Standard_Boolean              m_TriedronVisible;
-  vtkActorCollection*           m_Triedron;  
-
+  VTKViewer_Trihedron *m_Triedron;  
   SALOME_Transform *m_Transform;
 };
 #endif