Salome HOME
Merge with branch V2_2_0_VISU_improvement
authorjfa <jfa@opencascade.com>
Wed, 13 Jul 2005 12:08:32 +0000 (12:08 +0000)
committerjfa <jfa@opencascade.com>
Wed, 13 Jul 2005 12:08:32 +0000 (12:08 +0000)
14 files changed:
src/SVTK/Makefile.in
src/SVTK/SVTK_CubeAxesActor2D.cxx [new file with mode: 0644]
src/SVTK/SVTK_CubeAxesActor2D.h [new file with mode: 0644]
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_RenderWindowInteractor.cxx
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h
src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx
src/VTKViewer/VTKViewer_Transform.cxx
src/VTKViewer/VTKViewer_Transform.h
src/VTKViewer/VTKViewer_Utilities.cxx
src/VTKViewer/VTKViewer_Utilities.h
src/VTKViewer/VTKViewer_ViewWindow.cxx

index 806e7996428ec3de6b3a149ea922bb75677899b7..e41cfb610c370449e5c687ba14a8b6c5e53934d1 100755 (executable)
@@ -15,6 +15,7 @@ VPATH=.:@srcdir@
 EXPORT_HEADERS= SVTK.h \
                SVTK_Prs.h \
                SVTK_Actor.h \
+               SVTK_CubeAxesActor2D.h \
                SVTK_Functor.h \
                SVTK_ViewManager.h \
                SVTK_ViewModel.h \
@@ -22,13 +23,15 @@ EXPORT_HEADERS= SVTK.h \
                SVTK_RenderWindow.h \
                SVTK_InteractorStyle.h \
                SVTK_RenderWindowInteractor.h \
-               SVTK_Selector.h SVTK_Selection.h
+               SVTK_Selector.h \
+               SVTK_Selection.h
 
 # 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 \
diff --git a/src/SVTK/SVTK_CubeAxesActor2D.cxx b/src/SVTK/SVTK_CubeAxesActor2D.cxx
new file mode 100644 (file)
index 0000000..55eb8df
--- /dev/null
@@ -0,0 +1,648 @@
+//  SALOME OBJECT : kernel of SALOME 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_CubeAxesActor2D.cxx
+//  Author : Eugeny Nikolaev
+//  Module : SALOME
+//  $Header$
+
+#include "SVTK_CubeAxesActor2D.h"
+#include "VTKViewer_Transform.h"
+
+#include <vtkPolyDataMapper.h>
+#include <vtkRectilinearGridGeometryFilter.h>
+#include <vtkActor.h>
+#include <vtkCubeAxesActor2D.h>
+#include <vtkAxisActor2D.h>
+#include <vtkCamera.h>
+#include <vtkDataSet.h>
+#include <vtkMath.h>
+#include <vtkObjectFactory.h>
+#include <vtkTextProperty.h>
+#include <vtkViewport.h>
+#include <vtkFloatArray.h>
+#include <vtkRectilinearGrid.h>
+#include <vtkProperty.h>
+#include <vtkProperty2D.h>
+
+vtkCxxRevisionMacro(SVTK_CubeAxesActor2D, "$Revision$");
+vtkStandardNewMacro(SVTK_CubeAxesActor2D);
+
+//----------------------------------------------------------------------------
+// Instantiate this object.
+SVTK_CubeAxesActor2D::SVTK_CubeAxesActor2D()
+{
+  this->wireActorXY = vtkActor::New();
+  this->wireActorYZ = vtkActor::New();
+  this->wireActorXZ = vtkActor::New();
+
+  this->planeXY = vtkRectilinearGridGeometryFilter::New();
+  this->planeYZ = vtkRectilinearGridGeometryFilter::New();
+  this->planeXZ = vtkRectilinearGridGeometryFilter::New();
+
+  this->rgridMapperXY = vtkPolyDataMapper::New();
+  this->rgridMapperYZ = vtkPolyDataMapper::New();
+  this->rgridMapperXZ = vtkPolyDataMapper::New();
+
+  this->rgridMapperXY->SetInput(this->planeXY->GetOutput());
+  this->rgridMapperYZ->SetInput(this->planeYZ->GetOutput());
+  this->rgridMapperXZ->SetInput(this->planeXZ->GetOutput());
+
+  this->wireActorXY->SetMapper(rgridMapperXY);
+  this->wireActorYZ->SetMapper(rgridMapperYZ);
+  this->wireActorXZ->SetMapper(rgridMapperXZ);
+
+  this->wireActorXY->GetProperty()->SetRepresentationToWireframe();
+  this->wireActorYZ->GetProperty()->SetRepresentationToWireframe();
+  this->wireActorXZ->GetProperty()->SetRepresentationToWireframe();
+
+  // setting ambient to 1 (if no - incorrect reaction on light)
+  this->wireActorXY->GetProperty()->SetAmbient(1);
+  this->wireActorYZ->GetProperty()->SetAmbient(1);
+  this->wireActorXZ->GetProperty()->SetAmbient(1);
+
+  this->XAxis->SetTitle(this->XLabel);
+  this->YAxis->SetTitle(this->YLabel);
+  this->ZAxis->SetTitle(this->ZLabel);
+  
+  this->XAxis->SetNumberOfLabels(this->NumberOfLabels);
+  this->YAxis->SetNumberOfLabels(this->NumberOfLabels);
+  this->ZAxis->SetNumberOfLabels(this->NumberOfLabels);
+  this->XAxis->SetLabelFormat(this->LabelFormat);
+  this->YAxis->SetLabelFormat(this->LabelFormat);
+  this->ZAxis->SetLabelFormat(this->LabelFormat);
+  
+  this->XAxis->SetFontFactor(this->FontFactor);
+  this->YAxis->SetFontFactor(this->FontFactor);
+  this->ZAxis->SetFontFactor(this->FontFactor);
+  
+  this->XAxis->SetProperty(this->GetProperty());
+  this->YAxis->SetProperty(this->GetProperty());
+  this->ZAxis->SetProperty(this->GetProperty());
+
+  vtkTextProperty* aTLProp = vtkTextProperty::New();
+  aTLProp->SetBold(0);
+  aTLProp->SetItalic(0);
+  aTLProp->SetShadow(0);
+  aTLProp->SetFontFamilyToArial();
+  aTLProp->SetColor(1,0,0);
+  if (this->XAxis->GetLabelTextProperty())
+    this->XAxis->GetLabelTextProperty()->ShallowCopy(aTLProp);
+  aTLProp->SetColor(0,1,0);
+  if (this->YAxis->GetLabelTextProperty())
+    this->YAxis->GetLabelTextProperty()->ShallowCopy(aTLProp);
+  aTLProp->SetColor(0,0,1);
+  if (this->ZAxis->GetLabelTextProperty())
+    this->ZAxis->GetLabelTextProperty()->ShallowCopy(aTLProp);;
+
+  aTLProp->SetColor(1,0,0);
+  if (this->XAxis->GetLabelTextProperty())
+    this->XAxis->GetTitleTextProperty()->ShallowCopy(aTLProp);
+  aTLProp->SetColor(0,1,0);
+  if (this->YAxis->GetLabelTextProperty())
+    this->YAxis->GetTitleTextProperty()->ShallowCopy(aTLProp);
+  aTLProp->SetColor(0,0,1);
+  if (this->ZAxis->GetLabelTextProperty())
+    this->ZAxis->GetTitleTextProperty()->ShallowCopy(aTLProp);
+  
+  aTLProp->Delete();
+  
+}
+
+//----------------------------------------------------------------------------
+SVTK_CubeAxesActor2D::~SVTK_CubeAxesActor2D()
+{
+  this->wireActorXY->Delete();
+  this->wireActorYZ->Delete();
+  this->wireActorXZ->Delete();
+
+  this->planeXY->Delete();
+  this->planeYZ->Delete();
+  this->planeXZ->Delete();
+
+  this->rgridMapperXY->Delete();
+  this->rgridMapperYZ->Delete();
+  this->rgridMapperXZ->Delete();
+}
+
+//----------------------------------------------------------------------------
+// Static variable describes connections in cube.
+static int Conn[8][3] = {{1,2,4}, {0,3,5}, {3,0,6}, {2,1,7},
+                         {5,6,0}, {4,7,1}, {7,4,2}, {6,5,3}};
+
+//----------------------------------------------------------------------------
+// Project the bounding box and compute edges on the border of the bounding
+// cube. Determine which parts of the edges are visible via intersection 
+// with the boundary of the viewport (minus borders).
+int SVTK_CubeAxesActor2D::RenderOverlay(vtkViewport *viewport)
+{
+  int renderedSomething=0;
+
+  // Initialization
+  if ( ! this->RenderSomething )
+    {
+    return 0;
+    }
+  
+  //Render the axes
+  if ( this->XAxisVisibility )
+    {
+    renderedSomething += this->XAxis->RenderOverlay(viewport);
+    }
+  if ( this->YAxisVisibility )
+    {
+    renderedSomething += this->YAxis->RenderOverlay(viewport);
+    }
+  if ( this->ZAxisVisibility )
+    {
+    renderedSomething += this->ZAxis->RenderOverlay(viewport);
+    }
+  
+  bool RX=false,RY=false;
+  if (this->XAxisVisibility){
+    this->wireActorXY->RenderOverlay(viewport);
+    this->wireActorXZ->RenderOverlay(viewport);
+    RX = true;
+  }
+  if (this->YAxisVisibility){
+    if(!RX) this->wireActorXY->RenderOverlay(viewport);
+    this->wireActorYZ->RenderOverlay(viewport);
+    RY = true;
+  }
+  if (this->ZAxisVisibility){
+    if(!RX) this->wireActorXZ->RenderOverlay(viewport);
+    if(!RY) this->wireActorYZ->RenderOverlay(viewport);
+  }
+
+  return renderedSomething;
+}
+
+static void ChangeValues(float* aArray1,float* aArray2,float *aRange1,float* aRange2,bool theY){
+  float tmp=-1000;
+  if (!theY){
+    for (int i=0; i<4; i++){
+      tmp = aArray1[i]; aArray1[i] = aArray2[i]; aArray2[i] = tmp;
+    }
+    for(int i=0;i<2; i++){
+      tmp = aRange1[i]; aRange1[i] = aRange2[i]; aRange2[i] = tmp;
+    }
+  }
+  else{
+    tmp = aArray1[2]; aArray1[2] = aArray2[0]; aArray2[0] = tmp;
+    tmp = aArray1[3]; aArray1[3] = aArray2[1]; aArray2[1] = tmp;
+    tmp = aArray1[0]; aArray1[0] = aArray2[2]; aArray2[2] = tmp;
+    tmp = aArray1[1]; aArray1[1] = aArray2[3]; aArray2[3] = tmp;
+
+    tmp = aRange1[0]; aRange1[0] = aRange2[1]; aRange2[1] = tmp;
+    tmp = aRange1[1]; aRange1[1] = aRange2[0]; aRange2[0] = tmp;
+  }
+}
+
+static void ChangeArrays(float* xCoords,float* yCoords,float* zCoords,
+                        float* xRange,float* yRange,float* zRange,
+                        const int xAxes,const int yAxes, const int zAxes)
+{
+  if ( xAxes == 0 && yAxes == 2 && zAxes == 1)
+    ChangeValues(yCoords,zCoords,yRange,zRange,true);
+  else if (xAxes == 1 && yAxes == 0 && zAxes == 2)
+    ChangeValues(xCoords,yCoords,xRange,yRange,true);
+  else if (xAxes == 1 && yAxes == 2 && zAxes == 0){
+    ChangeValues(xCoords,zCoords,xRange,zRange,false);
+    // xAxes == 0 && yAxes == 2 && zAxes == 1
+    ChangeValues(yCoords,zCoords,yRange,zRange,true);
+  } else if (xAxes == 2 && yAxes == 0 && zAxes == 1){
+    ChangeValues(xCoords,yCoords,xRange,yRange,true);
+    // xAxes == 0 && yAxes == 2 && zAxes == 1
+    ChangeValues(zCoords,yCoords,zRange,yRange,true);
+  } else if (xAxes == 2 && yAxes == 1 && zAxes == 0)
+    ChangeValues(zCoords,xCoords,zRange,xRange,false);
+}
+
+//----------------------------------------------------------------------------
+// Project the bounding box and compute edges on the border of the bounding
+// cube. Determine which parts of the edges are visible via intersection 
+// with the boundary of the viewport (minus borders).
+int SVTK_CubeAxesActor2D::RenderOpaqueGeometry(vtkViewport *viewport)
+{
+  float bounds[6], slope = 0.0, minSlope, num, den;
+  float pts[8][3], d2, d2Min, min;
+  int i, idx = 0;
+  int xIdx, yIdx = 0, zIdx = 0, zIdx2, renderedSomething=0;
+  int xAxes = 0, yAxes, zAxes;
+
+  // Initialization
+  if ( !this->Camera )
+    {
+    vtkErrorMacro(<<"No camera!");
+    this->RenderSomething = 0;
+    return 0;
+    }
+  
+  this->RenderSomething = 1;
+
+  // determine the bounds to use
+  this->GetBounds(bounds);
+
+  // Build the axes (almost always needed so we don't check mtime)
+  // Transform all points into display coordinates
+  this->TransformBounds(viewport, bounds, pts);
+
+  // Find the portion of the bounding box that fits within the viewport,
+  if ( this->ClipBounds(viewport, pts, bounds) == 0 )
+    {
+    this->RenderSomething = 0;
+    return 0;
+    }
+
+  // Take into account the inertia. Process only so often.
+  if ( this->RenderCount++ == 0 || !(this->RenderCount % this->Inertia) )
+    {
+    // Okay, we have a bounding box, maybe clipped and scaled, that is visible.
+    // We setup the axes depending on the fly mode.
+    if ( this->FlyMode == VTK_FLY_CLOSEST_TRIAD )
+      {
+      // Loop over points and find the closest point to the camera
+      min = VTK_LARGE_FLOAT;
+      for (i=0; i < 8; i++)
+        {
+        if ( pts[i][2] < min )
+          {
+          idx = i;
+          min = pts[i][2];
+          }
+        }
+
+      // Setup the three axes to be drawn
+      xAxes = 0;
+      xIdx = Conn[idx][0];
+      yAxes = 1;
+      yIdx = Conn[idx][1];
+      zAxes = 2;
+      zIdx = idx;
+      zIdx2 = Conn[idx][2];
+      }
+    else
+      {
+      float e1[2], e2[2], e3[2];
+
+      // Find distance to origin
+      d2Min = VTK_LARGE_FLOAT;
+      for (i=0; i < 8; i++)
+        {
+        d2 = pts[i][0]*pts[i][0] + pts[i][1]*pts[i][1];
+        if ( d2 < d2Min )
+          {
+          d2Min = d2;
+          idx = i;
+          }
+        }
+
+      // find minimum slope point connected to closest point and on 
+      // right side (in projected coordinates). This is the first edge.
+      minSlope = VTK_LARGE_FLOAT;
+      for (xIdx=0, i=0; i<3; i++)
+        {
+        num = (pts[Conn[idx][i]][1] - pts[idx][1]);
+        den = (pts[Conn[idx][i]][0] - pts[idx][0]);
+        if ( den != 0.0 )
+          {
+          slope = num / den;
+          }
+        if ( slope < minSlope && den > 0 )
+          {
+          xIdx = Conn[idx][i];
+          yIdx = Conn[idx][(i+1)%3];
+          zIdx = Conn[idx][(i+2)%3];
+          xAxes = i;
+          minSlope = slope;
+          }
+        }
+
+      // find edge (connected to closest point) on opposite side
+      for ( i=0; i<2; i++)
+        {
+        e1[i] = (pts[xIdx][i] - pts[idx][i]);
+        e2[i] = (pts[yIdx][i] - pts[idx][i]);
+        e3[i] = (pts[zIdx][i] - pts[idx][i]);
+        }
+      vtkMath::Normalize2D(e1);
+      vtkMath::Normalize2D(e2);
+      vtkMath::Normalize2D(e3);
+
+      if ( vtkMath::Dot2D(e1,e2) < vtkMath::Dot2D(e1,e3) )
+        {
+        yAxes = (xAxes + 1) % 3;
+        }
+      else
+        {
+        yIdx = zIdx;
+        yAxes = (xAxes + 2) % 3;
+        }
+
+      // Find the final point by determining which global x-y-z axes have not 
+      // been represented, and then determine the point closest to the viewer.
+      zAxes = (xAxes != 0 && yAxes != 0 ? 0 :
+              (xAxes != 1 && yAxes != 1 ? 1 : 2));
+      if ( pts[Conn[xIdx][zAxes]][2] < pts[Conn[yIdx][zAxes]][2] )
+        {
+        zIdx = xIdx;
+        zIdx2 = Conn[xIdx][zAxes];
+        }
+      else
+        {
+        zIdx = yIdx;
+        zIdx2 = Conn[yIdx][zAxes];
+        }
+      }//else boundary edges fly mode
+    this->InertiaAxes[0] = idx;
+    this->InertiaAxes[1] = xIdx;
+    this->InertiaAxes[2] = yIdx;
+    this->InertiaAxes[3] = zIdx;
+    this->InertiaAxes[4] = zIdx2;
+    this->InertiaAxes[5] = xAxes;
+    this->InertiaAxes[6] = yAxes;
+    this->InertiaAxes[7] = zAxes;
+    } //inertia
+  else
+    {
+    idx = this->InertiaAxes[0];
+    xIdx = this->InertiaAxes[1];
+    yIdx = this->InertiaAxes[2];
+    zIdx = this->InertiaAxes[3];
+    zIdx2 = this->InertiaAxes[4];
+    xAxes = this->InertiaAxes[5];
+    yAxes = this->InertiaAxes[6];
+    zAxes = this->InertiaAxes[7];
+    }
+
+  // Setup the axes for plotting
+  float xCoords[4], yCoords[4], zCoords[4], xRange[2], yRange[2], zRange[2];
+  this->AdjustAxes(pts, bounds, idx, xIdx, yIdx, zIdx, zIdx2, 
+                   xAxes, yAxes, zAxes, 
+                   xCoords, yCoords, zCoords, xRange, yRange, zRange);
+
+  // Upate axes
+  this->Labels[0] = this->XLabel;
+  this->Labels[1] = this->YLabel;
+  this->Labels[2] = this->ZLabel;
+
+  // correct XAxis, YAxis, ZAxis, which must be 
+  // parallel OX, OY, OZ system coordinates
+  // if xAxes=0 yAxes=1 zAxes=2 - good situation
+  if (!(xAxes == 0 && yAxes == 1 && zAxes == 2))
+    ChangeArrays(xCoords,yCoords,zCoords,
+                xRange,yRange,zRange,
+                xAxes,yAxes,zAxes);
+
+  double aTScale[3];
+  if(m_Transform.GetPointer() != NULL)
+    m_Transform->GetMatrixScale(aTScale);
+
+  this->XAxis->GetPositionCoordinate()->SetValue(xCoords[0], xCoords[1]);
+  this->XAxis->GetPosition2Coordinate()->SetValue(xCoords[2], xCoords[3]);
+  if(m_Transform.GetPointer() != NULL) this->XAxis->SetRange(xRange[0]/aTScale[0], xRange[1]/aTScale[0]);
+  else this->XAxis->SetRange(xRange[0], xRange[1]);
+
+  this->YAxis->GetPositionCoordinate()->SetValue(yCoords[2], yCoords[3]);
+  this->YAxis->GetPosition2Coordinate()->SetValue(yCoords[0], yCoords[1]);
+  if(m_Transform.GetPointer() != NULL) this->YAxis->SetRange(yRange[1]/aTScale[1], yRange[0]/aTScale[1]);
+  else this->YAxis->SetRange(yRange[1], yRange[0]);
+
+  this->ZAxis->GetPositionCoordinate()->SetValue(zCoords[0], zCoords[1]);
+  this->ZAxis->GetPosition2Coordinate()->SetValue(zCoords[2], zCoords[3]);
+  if(m_Transform.GetPointer() != NULL) this->ZAxis->SetRange(zRange[0]/aTScale[2], zRange[1]/aTScale[2]);
+  else this->ZAxis->SetRange(zRange[0], zRange[1]);
+
+  int numOfLabelsX = this->XAxis->GetNumberOfLabels();
+  int numOfLabelsY = this->YAxis->GetNumberOfLabels();
+  int numOfLabelsZ = this->ZAxis->GetNumberOfLabels();
+
+  // XCoords coordinates for X grid
+  vtkFloatArray *XCoords = vtkFloatArray::New();
+  for(int i=0;i<numOfLabelsX;i++){
+    float val = bounds[0]+i*(bounds[1]-bounds[0])/(numOfLabelsX-1);
+    XCoords->InsertNextValue(val);
+  }
+  // YCoords coordinates for Y grid
+  vtkFloatArray *YCoords = vtkFloatArray::New();
+  for(int i=0;i<numOfLabelsX;i++){
+    float val = bounds[2]+i*(bounds[3]-bounds[2])/(numOfLabelsY-1);
+    YCoords->InsertNextValue(val);
+  }
+  // ZCoords coordinates for Z grid
+  vtkFloatArray *ZCoords = vtkFloatArray::New();
+  for(int i=0;i<numOfLabelsZ;i++){
+    float val = bounds[4]+i*(bounds[5]-bounds[4])/(numOfLabelsZ-1);
+    ZCoords->InsertNextValue(val);
+  }
+
+  vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();
+  rgrid->SetDimensions(numOfLabelsX,numOfLabelsY,numOfLabelsZ);
+  rgrid->SetXCoordinates(XCoords);
+  rgrid->SetYCoordinates(YCoords);
+  rgrid->SetZCoordinates(ZCoords);
+
+  this->planeXY->SetInput(rgrid);
+  this->planeYZ->SetInput(rgrid);
+  this->planeXZ->SetInput(rgrid);
+
+  rgrid->Delete();
+
+  float aCPosition[3];
+  float aCDirection[3];
+  this->Camera->GetPosition(aCPosition);
+  this->Camera->GetDirectionOfProjection(aCDirection);
+
+  // culculate placement of XY
+  bool replaceXY=false;
+  bool replaceYZ=false;
+  bool replaceXZ=false;
+  float p[6][3]; // centers of planes
+  float vecs[6][3]; // 6 vectors from camera position to centers
+
+  float aMiddleX = (XCoords->GetValue(0) + XCoords->GetValue(numOfLabelsX-1))/2;
+  float aMiddleY = (YCoords->GetValue(0) + YCoords->GetValue(numOfLabelsY-1))/2;
+  float aMiddleZ = (ZCoords->GetValue(0) + ZCoords->GetValue(numOfLabelsZ-1))/2;
+
+  // plane XY
+  p[0][0] = aMiddleX; // plane X=0.5 Y=0.5 Z=0
+  p[0][1] = aMiddleY;
+  p[0][2] = ZCoords->GetValue(0);
+
+  p[1][0] = aMiddleX; // plane X=0.5 Y=0.5 Z=1
+  p[1][1] = aMiddleY;
+  p[1][2] = ZCoords->GetValue(numOfLabelsZ-1);
+
+  // plane YZ
+  p[2][0] = XCoords->GetValue(0); // plane X=0 Y=0.5 Z=0.5
+  p[2][1] = aMiddleY;
+  p[2][2] = aMiddleZ;
+
+  p[3][0] = XCoords->GetValue(numOfLabelsX-1);
+  p[3][1] = aMiddleY;
+  p[3][2] = aMiddleZ;
+
+  // plane XZ
+  p[4][0] = aMiddleX; // plane X=0.5 Y=0 Z=0.5
+  p[4][1] = YCoords->GetValue(0);
+  p[4][2] = aMiddleZ;
+
+  p[5][0] = aMiddleX; // plane X=0.5 Y=1 Z=0.5
+  p[5][1] = YCoords->GetValue(numOfLabelsY-1);
+  p[5][2] = aMiddleZ;
+
+  for(int i=0;i<3;i++) 
+    for(int j=0;j<6;j++) vecs[j][i] = p[j][i] - aCPosition[i];
+
+  if ( vtkMath::Dot(vecs[0],aCDirection) < vtkMath::Dot(vecs[1],aCDirection))
+    replaceXY = true;
+  if ( vtkMath::Dot(vecs[2],aCDirection) < vtkMath::Dot(vecs[3],aCDirection))
+    replaceYZ = true;
+  if ( vtkMath::Dot(vecs[4],aCDirection) < vtkMath::Dot(vecs[5],aCDirection))
+    replaceXZ = true;
+
+  if(replaceXY) this->planeXY->SetExtent(0,numOfLabelsX, 0,numOfLabelsY, numOfLabelsZ,numOfLabelsZ);
+  else this->planeXY->SetExtent(0,numOfLabelsX, 0,numOfLabelsY, 0,0);
+
+  if(replaceYZ) this->planeYZ->SetExtent(numOfLabelsX,numOfLabelsX, 0,numOfLabelsY, 0,numOfLabelsZ);
+  else this->planeYZ->SetExtent(0,0, 0,numOfLabelsY, 0,numOfLabelsZ);
+
+  if(replaceXZ) this->planeXZ->SetExtent(0,numOfLabelsX, numOfLabelsY,numOfLabelsY, 0,numOfLabelsZ);
+  else this->planeXZ->SetExtent(0,numOfLabelsX, 0,0, 0,numOfLabelsZ);
+
+  XCoords->Delete();
+  YCoords->Delete();
+  ZCoords->Delete();
+
+  float color[3];
+
+  this->GetProperty()->GetColor(color);
+  this->wireActorXY->GetProperty()->SetColor(color);
+  this->wireActorYZ->GetProperty()->SetColor(color);
+  this->wireActorXZ->GetProperty()->SetColor(color);
+
+  /*
+  // Rebuid text props
+  // Perform shallow copy here since each individual axis can be
+  // accessed through the class API (i.e. each individual axis text prop
+  // can be changed). Therefore, we can not just assign pointers otherwise
+  // each individual axis text prop would point to the same text prop.
+
+  if (this->AxisLabelTextProperty &&
+      this->AxisLabelTextProperty->GetMTime() > this->BuildTime)
+    {
+    if (this->XAxis->GetLabelTextProperty())
+      {
+      this->XAxis->GetLabelTextProperty()->ShallowCopy(
+        this->AxisLabelTextProperty);
+      }
+    if (this->YAxis->GetLabelTextProperty())
+      {
+      this->YAxis->GetLabelTextProperty()->ShallowCopy(
+        this->AxisLabelTextProperty);
+      }
+    if (this->ZAxis->GetLabelTextProperty())
+      {
+      this->ZAxis->GetLabelTextProperty()->ShallowCopy(
+        this->AxisLabelTextProperty);
+      }
+    }
+
+  if (this->AxisTitleTextProperty &&
+      this->AxisTitleTextProperty->GetMTime() > this->BuildTime)
+    {
+    if (this->XAxis->GetLabelTextProperty())
+      {
+      this->XAxis->GetTitleTextProperty()->ShallowCopy(
+        this->AxisTitleTextProperty);
+      }
+    if (this->YAxis->GetLabelTextProperty())
+      {
+      this->YAxis->GetTitleTextProperty()->ShallowCopy(
+        this->AxisTitleTextProperty);
+      }
+    if (this->ZAxis->GetLabelTextProperty())
+      {
+      this->ZAxis->GetTitleTextProperty()->ShallowCopy(
+        this->AxisTitleTextProperty);
+      }
+    }
+  */  
+  this->BuildTime.Modified();
+
+  //Render the axes
+  if ( this->XAxisVisibility )
+  {
+    renderedSomething += this->XAxis->RenderOpaqueGeometry(viewport);
+  }
+  if ( this->YAxisVisibility )
+  {
+    renderedSomething += this->YAxis->RenderOpaqueGeometry(viewport);
+  }
+  if ( this->ZAxisVisibility )
+  {
+    renderedSomething += this->ZAxis->RenderOpaqueGeometry(viewport);
+  }
+
+  bool RX=false,RY=false;
+  if (this->XAxisVisibility){
+    this->wireActorXY->RenderOpaqueGeometry(viewport);
+    this->wireActorXZ->RenderOpaqueGeometry(viewport);
+    RX = true;
+  }
+  if (this->YAxisVisibility){
+    if(!RX) this->wireActorXY->RenderOpaqueGeometry(viewport);
+    this->wireActorYZ->RenderOpaqueGeometry(viewport);
+    RY = true;
+  }
+  if (this->ZAxisVisibility){
+    if(!RX) this->wireActorXZ->RenderOpaqueGeometry(viewport);
+    if(!RY) this->wireActorYZ->RenderOpaqueGeometry(viewport);
+  }
+
+  return renderedSomething;
+}
+
+//----------------------------------------------------------------------------
+// Release any graphics resources that are being consumed by this actor.
+// The parameter window could be used to determine which graphic
+// resources to release.
+void SVTK_CubeAxesActor2D::ReleaseGraphicsResources(vtkWindow *win)
+{
+  this->XAxis->ReleaseGraphicsResources(win);
+  this->YAxis->ReleaseGraphicsResources(win);
+  this->ZAxis->ReleaseGraphicsResources(win);
+
+  this->wireActorXY->ReleaseGraphicsResources(win);
+  this->wireActorYZ->ReleaseGraphicsResources(win);
+  this->wireActorXZ->ReleaseGraphicsResources(win);
+}
+
+void SVTK_CubeAxesActor2D::SetTransform(VTKViewer_Transform* theTransform){
+  this->m_Transform = theTransform;
+}
+
+VTKViewer_Transform* SVTK_CubeAxesActor2D::GetTransform(){
+  return (this->m_Transform.GetPointer());
+}
diff --git a/src/SVTK/SVTK_CubeAxesActor2D.h b/src/SVTK/SVTK_CubeAxesActor2D.h
new file mode 100644 (file)
index 0000000..69d5efd
--- /dev/null
@@ -0,0 +1,102 @@
+//  SALOME OBJECT : kernel of SALOME 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_CubeAxesActor2D.h
+//  Author : Eugeny Nikolaev
+//  Module : SALOME
+//  $Header$
+
+#ifndef __SVTK_CubeAxesActor2D_h
+#define __SVTK_CubeAxesActor2D_h
+
+#include <vtkCubeAxesActor2D.h>
+#include <vtkSmartPointer.h>
+
+class vtkActor;
+class vtkAxisActor2D;
+class vtkCamera;
+class vtkDataSet;
+class vtkTextProperty;
+class vtkPolyDataMapper;
+class vtkRectilinearGridGeometryFilter;
+class VTKViewer_Transform;
+
+class VTK_HYBRID_EXPORT SVTK_CubeAxesActor2D : public vtkCubeAxesActor2D
+{
+public:
+  vtkTypeRevisionMacro(SVTK_CubeAxesActor2D,vtkCubeAxesActor2D);
+
+  // Description:
+  // Instantiate object with bold, italic, and shadow enabled; font family
+  // set to Arial; and label format "6.3g". The number of labels per axis
+  // is set to 3.
+  static SVTK_CubeAxesActor2D *New();
+  
+  // Description:
+  // Draw the axes as per the vtkProp superclass' API.
+  int RenderOverlay(vtkViewport*);
+  int RenderOpaqueGeometry(vtkViewport*);
+
+  // Description:
+  // Release any graphics resources that are being consumed by this actor.
+  // The parameter window could be used to determine which graphic
+  // resources to release.
+  void ReleaseGraphicsResources(vtkWindow *);
+
+  // Description:
+  
+  vtkActor* GetWireActorXY(){return this->wireActorXY;}
+  vtkActor* GetWireActorYZ(){return this->wireActorYZ;}
+  vtkActor* GetWireActorXZ(){return this->wireActorXZ;}
+
+  void SetTransform(VTKViewer_Transform* theTransform);
+  VTKViewer_Transform* GetTransform();
+  
+protected:
+  SVTK_CubeAxesActor2D();
+  ~SVTK_CubeAxesActor2D();
+
+  vtkActor* wireActorXY;
+  vtkActor* wireActorYZ;
+  vtkActor* wireActorXZ;
+
+private:
+  // hide the superclass' ShallowCopy() from the user and the compiler.
+  void ShallowCopy(vtkProp *prop) { this->vtkProp::ShallowCopy( prop ); };
+
+  vtkRectilinearGridGeometryFilter *planeXY; // rectilinear grid XY
+  vtkPolyDataMapper *rgridMapperXY;
+  
+  vtkRectilinearGridGeometryFilter *planeYZ; // rectilinear grid YZ
+  vtkPolyDataMapper *rgridMapperYZ;
+
+  vtkRectilinearGridGeometryFilter *planeXZ; // rectilinear grid XZ
+  vtkPolyDataMapper *rgridMapperXZ;
+  
+  vtkSmartPointer<VTKViewer_Transform> m_Transform;
+private:
+  SVTK_CubeAxesActor2D(const SVTK_CubeAxesActor2D&);  // Not implemented.
+  void operator=(const SVTK_CubeAxesActor2D&);  // Not implemented.
+};
+
+#endif
index 77338f4b1cfb7c071c3b38f2d4074f4a573c703a..c4d585b75ca7b939ea28343753b65f2309b4a16e 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "VTKViewer_CellRectPicker.h"
 #include "VTKViewer_Utilities.h"
-#include "VTKViewer_Trihedron.h"
 #include "VTKViewer_RectPicker.h"
 
 #include "SVTK_RenderWindowInteractor.h"
@@ -129,7 +128,6 @@ vtkStandardNewMacro(SVTK_InteractorStyle);
 SVTK_InteractorStyle
 ::SVTK_InteractorStyle() 
 {
-  myTrihedron = NULL;
   myViewWindow = NULL;
   this->MotionFactor = 10.0;
   this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
@@ -211,14 +209,6 @@ SVTK_InteractorStyle
   myGUIWindow = theWindow;
 }
 
-//----------------------------------------------------------------------------
-void
-SVTK_InteractorStyle
-::setTriedron(VTKViewer_Trihedron* theTrihedron)
-{
-  myTrihedron = theTrihedron;
-}
-
 //----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
@@ -675,30 +665,6 @@ SVTK_InteractorStyle
 }
 
 
-//----------------------------------------------------------------------------
-void  
-SVTK_InteractorStyle
-::ViewFitAll() 
-{
-  int aTriedronWasVisible = false;
-  if(myTrihedron){
-    aTriedronWasVisible = myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
-    if(aTriedronWasVisible) myTrihedron->VisibilityOff();
-  }
-
-  if(myTrihedron->GetVisibleActorCount(CurrentRenderer)){
-    myTrihedron->VisibilityOff();
-    ::ResetCamera(CurrentRenderer);
-  }else{
-    myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
-    ::ResetCamera(CurrentRenderer,true);
-  }
-  if(aTriedronWasVisible) myTrihedron->VisibilityOn();
-  else myTrihedron->VisibilityOff();
-  ::ResetCameraClippingRange(CurrentRenderer);
-}
-
-
 //----------------------------------------------------------------------------
 // starts Global Panning operation (e.g. through menu command)
 void
@@ -717,7 +683,7 @@ SVTK_InteractorStyle
   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
   myScale = cam->GetParallelScale();
 
-  ViewFitAll();
+  if (myViewWindow) myViewWindow->onFitAll();
 
   if (myGUIWindow) myGUIWindow->update();
   
@@ -1288,6 +1254,12 @@ SVTK_InteractorStyle
 
   SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
 
+  if (aSActor && myPreSelectionActor){
+    float aPos[3];
+    aSActor->GetPosition(aPos);
+    myPreSelectionActor->SetPosition(aPos);
+  }
+
   if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
     int aVtkId = picker->GetCellId();
     if ( aVtkId >= 0 ) {
index c82b592d5a6e87bb45f7ddfae726646df02021b8..53039e86b4f07cd6166fca025b99bfb4294c92ba 100644 (file)
@@ -80,7 +80,7 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject,
 
   virtual int GetState();
 
-  void setTriedron(VTKViewer_Trihedron* theTrihedron);
+  //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, 
@@ -97,7 +97,7 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject,
 
   void OnSelectionModeChanged();
 
-  void  ViewFitAll();
+  //merge with V2_2_0_VISU_improvements:void  ViewFitAll();
 
   void                     SetFilter( const Handle(VTKViewer_Filter)& );
   Handle(VTKViewer_Filter) GetFilter( const int );  
@@ -183,7 +183,7 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject,
   
   SVTK_RenderWindowInteractor* myInteractor;
   SVTK_ViewWindow*          myViewWindow;
-  VTKViewer_Trihedron*      myTrihedron;
+  //merge with V2_2_0_VISU_improvements:VTKViewer_Trihedron*      myTrihedron;
   QWidget*                  myGUIWindow;
   
   std::map<int, Handle(VTKViewer_Filter)> myFilters;
index 1b32fc424360a69d8c949849c097f79b80c0edc9..a80733492639df46b8de5244c69ff91eb1a4bfe7 100644 (file)
@@ -913,6 +913,9 @@ SVTK_RenderWindowInteractor
               TUpdateActor theFun)
 {
   (*theFun)(theMapIndex,theMapActor,theActor);
+  float aPos[3];
+  theMapActor->GetPosition(aPos);
+  theActor->SetPosition(aPos);
 }
 
 
index db554906776f4ea941b3c8bd1f5ef188c6914257..26b89496f309b637f107af90e2ff40feb2b0c901 100755 (executable)
@@ -2,6 +2,7 @@
 
 #include <qapplication.h>
 
+#include <vtkTextProperty.h>
 #include <vtkActorCollection.h>
 #include <vtkRenderWindow.h>
 #include <vtkRenderer.h>
@@ -20,6 +21,7 @@
 #include "VTKViewer_Utilities.h"
 
 #include "SVTK_Trihedron.h"
+#include "SVTK_CubeAxesActor2D.h"
 #include "SVTK_ViewWindow.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_RenderWindow.h"
@@ -46,9 +48,11 @@ SVTK_ViewWindow
 
   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);
@@ -83,11 +87,32 @@ SVTK_ViewWindow
   myRWInteractor->SetInteractorStyle( RWS ); 
   myRWInteractor->Initialize();
 
-  RWS->setTriedron( myTrihedron );
+  //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);
@@ -131,8 +156,9 @@ SVTK_ViewWindow
   
   //m_RW->Delete() ;
   myRenderer->RemoveAllProps();
-  //m_Renderer->Delete() ;
+  //m_Renderer->Delete();
   myTrihedron->Delete();
+  myCubeAxes->Delete();
 }
 
 //----------------------------------------------------------------------------
@@ -396,14 +422,23 @@ 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();
+
+  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();
@@ -414,7 +449,42 @@ void
 SVTK_ViewWindow
 ::onFitAll()
 {
-  myRWInteractor->GetSInteractorStyle()->ViewFitAll();
+  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();
 }
 
@@ -548,7 +618,7 @@ void
 SVTK_ViewWindow
 ::GetScale( double theScale[3] ) 
 {
-  myTransform->GetScale( theScale );
+  myTransform->GetMatrixScale( theScale );
 }
 
 //----------------------------------------------------------------------------
@@ -556,7 +626,7 @@ void
 SVTK_ViewWindow
 ::SetScale( double theScale[3] ) 
 {
-  myTransform->SetScale( theScale[0], theScale[1], theScale[2] );
+  myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
   myRWInteractor->Render();
   Repaint();
 }
@@ -569,6 +639,13 @@ SVTK_ViewWindow
   return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
 }
 
+bool
+SVTK_ViewWindow
+::isCubeAxesDisplayed()
+{
+  return myCubeAxes->GetVisibility() == 1;
+}
+
 //----------------------------------------------------------------------------
 void 
 SVTK_ViewWindow
@@ -585,8 +662,23 @@ SVTK_ViewWindow
   Repaint();
 }
 
+void
+SVTK_ViewWindow
+::onViewCubeAxes()
+{
+  if(!myCubeAxes)
+    return;
+
+  if(isCubeAxesDisplayed())
+    myCubeAxes->VisibilityOff();
+  else
+    myCubeAxes->VisibilityOn();
+
+  Repaint();
+}
+
 //----------------------------------------------------------------------------
-bool
+/*bool
 SVTK_ViewWindow
 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
 {
@@ -621,7 +713,7 @@ SVTK_ViewWindow
   // 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;
-}
+}*/
 
 //----------------------------------------------------------------------------
 int SVTK_ViewWindow::GetTrihedronSize() const
@@ -638,31 +730,79 @@ void SVTK_ViewWindow::SetTrihedronSize( const int sz )
   AdjustTrihedrons( true );
 }
 
+/*! If parameter theIsForcedUpdate is true, recalculate parameters for
+ *  trihedron and cube axes, even if trihedron and cube axes is invisible.
+ */
 void
 SVTK_ViewWindow
-::AdjustTrihedrons( const bool theIsForcedUpdate )
+::AdjustTrihedrons(const bool theIsForcedUpdate)
 {
-  if ( !isTrihedronDisplayed() && !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 );
-  if ( aVisibleNum || theIsForcedUpdate ) {
+  //if (aVisibleNum || theIsForcedUpdate) {
+  if (aVisibleNum) {
     // if the new trihedron size have sufficient difference, then apply the value
-    double aNewSize = 100, anOldSize;
-    if ( ComputeTrihedronSize( aNewSize, anOldSize ) || theIsForcedUpdate ) {
-      myTrihedron->SetSize( aNewSize );
-      // itearte throuh 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 );
+    double aNewSize = 100, anOldSize=myTrihedron->GetSize();
+    bool aTDisplayed = isTrihedronDisplayed();
+    bool aCDisplayed = isCubeAxesDisplayed();
+    if(aTDisplayed) myTrihedron->VisibilityOff();
+    if(aCDisplayed) myCubeAxes->VisibilityOff();
+
+    SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+    QString aSetting = aResMgr->stringValue("Viewer:TrihedronSize", "105");
+    static float aSizeInPercents = aSetting.toFloat();
+
+    //bool isComputeTrihedronSize =
+      ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
+
+    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);
 }
@@ -675,6 +815,13 @@ SVTK_ViewWindow
   AdjustTrihedrons( false );
 }
 
+void
+SVTK_ViewWindow
+::onAdjustCubeAxes()
+{   
+  AdjustTrihedrons(false);
+}
+
 #define INCREMENT_FOR_OP 10
 
 //=======================================================================
index c2ebd3b23abe71bad2de1490e655b7961a0b891f..2edda288e5291ed7a71103d03c8654db38a1a694 100755 (executable)
@@ -23,6 +23,7 @@ class SALOME_Actor;
 
 class SVTK_Viewer;
 class SVTK_Selector;
+class SVTK_CubeAxesActor2D;
 
 class SVTK_RenderWindow;
 class SVTK_InteractorStyle;
@@ -49,6 +50,7 @@ public:
   void SetSelectionMode(Selection_Mode theMode);
 
   bool isTrihedronDisplayed();
+  bool isCubeAxesDisplayed();
  
   /*  interactive object management */
   void highlight( const Handle(SALOME_InteractiveObject)& IObject, 
@@ -78,12 +80,15 @@ public:
   void RemoveActor(SALOME_Actor*, bool update = false);
 
   void AdjustTrihedrons( const bool forced );
-  bool ComputeTrihedronSize( double& theNewSize,
-                            double& theOldSize );
+  //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;};
+
 public slots:
   void onSelectionChanged();
 
@@ -102,7 +107,10 @@ public slots:
   void onFitAll();
 
   void onViewTrihedron(); 
+  void onViewCubeAxes();
+
   void onAdjustTrihedron();
+  void onAdjustCubeAxes();
  
   void onPanLeft();
   void onPanRight();
@@ -154,9 +162,10 @@ private:
   SVTK_RenderWindow* myRenderWindow;
   SVTK_RenderWindowInteractor* myRWInteractor;
 
-  VTKViewer_Transform* myTransform;
-  VTKViewer_Trihedron* myTrihedron;  
-  int                  myTrihedronSize;
+  VTKViewer_Transform*  myTransform;
+  VTKViewer_Trihedron*  myTrihedron;  
+  int                   myTrihedronSize;
+  SVTK_CubeAxesActor2D* myCubeAxes;
   
   QToolBar* myToolBar;
   ActionsMap myActionsMap;  
index 149c074c5ce008d629f561268dd71143cd245c57..de9bad8293812fec9785e1d724a41cadb5019a6e 100755 (executable)
@@ -583,11 +583,12 @@ bool VTKViewer_RenderWindowInteractor::highlight(const TColStd_IndexedMapOfInteg
 }
 
 void VTKViewer_RenderWindowInteractor::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
-                                                   VTKViewer_Actor* theMapActor,
-                                                   VTKViewer_Actor *theActor,
+                                                   VTKViewer_Actor * theMapActor,
+                                                   VTKViewer_Actor * theActor,
                                                    TUpdateActor theFun)
 {
   (*theFun)(theMapIndex,theMapActor,theActor);
+  float aPos[3];
+  theMapActor->GetPosition(aPos);
+  theActor->SetPosition(aPos);
 }
-
-
index 6001490e6c6992fbce3fe6707a1b1fdb7319dd28..63d60d66696ce52b3b44d175a1b7e95c970c329c 100755 (executable)
 #include <vtkObjectFactory.h>
 #include <vtkMatrix4x4.h>
 
+static double EPS = 10e-4;
+
 
 vtkStandardNewMacro(VTKViewer_Transform);
 
-void VTKViewer_Transform::SetScale(float theScaleX, float theScaleY, float theScaleZ){ 
+void VTKViewer_Transform::SetMatrixScale(double theScaleX, double theScaleY, double theScaleZ){ 
   double aMatrix[16] = {theScaleX,0,0,0, 
                         0,theScaleY,0,0, 
                         0,0,theScaleZ,0, 
                         0,0,0,1.0000000};
-  vtkTransform::SetMatrix(aMatrix);
+  this->SetMatrix(aMatrix);
+}
+
+void VTKViewer_Transform::GetMatrixScale(double theScale[3]){
+  vtkMatrix4x4 *aTMatrix=this->GetMatrix();
+  const double aScaleX = aTMatrix->GetElement(0,0);
+  const double aScaleY = aTMatrix->GetElement(1,1);
+  const double aScaleZ = aTMatrix->GetElement(2,2);
+  theScale[0] = aScaleX;
+  theScale[1] = aScaleY;
+  theScale[2] = aScaleZ;
 }
 
 int VTKViewer_Transform::IsIdentity(){ 
-  float* aScale = GetScale();
-  return (aScale[0] == 1.0 && aScale[1] == 1.0 && aScale[2] == 1.0);
+  double aScale[3];
+  this->GetMatrixScale(aScale);
+  return (fabs(aScale[0] - 1.0) < EPS && 
+         fabs(aScale[1] - 1.0) < EPS && 
+         fabs(aScale[2] - 1.0) < EPS);
 }
index 5192ef6a6a72faedad8e31d891179a831b7848b0..bbac32bf3ffc6a23fb2eb1a5d568541435b5d02c 100755 (executable)
@@ -12,7 +12,9 @@ public:
   vtkTypeMacro( VTKViewer_Transform, vtkTransform );
 
   int  IsIdentity();
-  void SetScale( float theScaleX, float theScaleY, float theScaleZ );
+  //merge with V2_2_0_VISU_improvements:void SetScale( float theScaleX, float theScaleY, float theScaleZ );
+  void SetMatrixScale(double theScaleX, double theScaleY, double theScaleZ);
+  void GetMatrixScale(double theScale[3]);
 
 protected:
   VTKViewer_Transform() {}
index afeb6c50432720e372807fd336093e5b417d820c..52c7bbcad0297dcbf5cc87dabaf93dd143d94d62 100755 (executable)
@@ -163,3 +163,27 @@ void ResetCameraClippingRange(vtkRenderer* theRenderer)
   
   anActiveCamera->SetClippingRange( range );
 }
+
+bool ComputeTrihedronSize( vtkRenderer* theRenderer,double& theNewSize,
+                          const double theSize, const float theSizeInPercents )
+{
+  // calculating diagonal of visible props of the renderer
+  float bnd[ 6 ];
+  if ( ComputeVisiblePropBounds( theRenderer, bnd ) == 0 )
+  {
+    bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100;
+    bnd[ 0 ] = bnd[ 2 ] = bnd[ 4 ] = 0;
+  }
+  float aLength = 0;
+
+  aLength = bnd[ 1 ]-bnd[ 0 ];
+  aLength = max( ( bnd[ 3 ] - bnd[ 2 ] ),aLength );
+  aLength = max( ( bnd[ 5 ] - bnd[ 4 ] ),aLength );
+
+  static float EPS_SIZE = 5.0E-3;
+  theNewSize = aLength * theSizeInPercents / 100.0;
+
+  // 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;
+}
index eb8b3ca1694791620e3678dcba804fa2cf14a155..24b837b8af3aa14887786eee11d5400705617641 100755 (executable)
@@ -6,6 +6,8 @@ class vtkRenderer;
 extern void  ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint = false);
 extern int   ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]);
 extern void  ResetCameraClippingRange(vtkRenderer* theRenderer);
+extern bool  ComputeTrihedronSize(vtkRenderer* theRenderer, double& theNewSize, 
+                                 const double theSize, const float theSizeInPercents);
 
 #ifndef max
 #define max(a,b)            (((a) > (b)) ? (a) : (b))
index f179eb92b87e2714fd1cddcecfd8d714c99dd667..11d52b4febb68a2fb45d99288e56a7d510596a31 100755 (executable)
@@ -420,7 +420,7 @@ void VTKViewer_ViewWindow::GetScale( double theScale[3] ) {
 }
 
 void VTKViewer_ViewWindow::SetScale( double theScale[3] ) {
-  myTransform->SetScale( theScale[0], theScale[1], theScale[2] );
+  myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
   myRWInteractor->Render();
   Repaint();
 }