Salome HOME
Moved some functionality to VTKViewer_Utilities.h
authorenk <enk@opencascade.com>
Mon, 23 May 2005 08:44:56 +0000 (08:44 +0000)
committerenk <enk@opencascade.com>
Mon, 23 May 2005 08:44:56 +0000 (08:44 +0000)
Cuted methods for Trihedron and CubeAxes fields in VTKViewer_ViewFrame class

src/VTKViewer/VTKViewer_Utilities.cxx
src/VTKViewer/VTKViewer_Utilities.h
src/VTKViewer/VTKViewer_ViewFrame.cxx
src/VTKViewer/VTKViewer_ViewFrame.h

index b8b61997f5b29f0c66785ec5343b0ee608d9dae0..4bde31f2ae8c28cac31a9244540817a7f3b7f5ec 100644 (file)
@@ -193,3 +193,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[ 100 ] = 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 e297ce7373a3687b0e05bc160c58c014d808b40c..6ecec095a38824f4ad20d23d5d9cda5ceb67f65b 100644 (file)
@@ -35,5 +35,7 @@ extern void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint = f
 extern int ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]);
 extern void ResetCameraClippingRange(vtkRenderer* theRenderer);
 extern float EPS_BNDBOX;
+extern bool ComputeTrihedronSize(vtkRenderer* theRenderer, double& theNewSize, 
+                                const double theSize, const float theSizeInPercents);
 
 #endif
index 1385ca4330ffd1017f93d88996ce8ec9da646d48..3fa967e2a0d4b67153d98700989e82f08bede3fb 100644 (file)
@@ -189,55 +189,15 @@ bool VTKViewer_ViewFrame::isCubeAxesDisplayed(){
   return m_CubeAxes->GetVisibility() == 1;
 }
 
-bool VTKViewer_ViewFrame::ComputeTrihedronSize( double& theNewSize, double& theSize )
-{
-  // calculating diagonal of visible props of the renderer
-  float bnd[ 6 ];
-  m_Triedron->VisibilityOff();
-  if ( ::ComputeVisiblePropBounds( m_Renderer, bnd ) == 0 )
-  {
-    bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100;
-    bnd[ 0 ] = bnd[ 2 ] = bnd[ 100 ] = 0;
-  }
-  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;
-  theSize = m_Triedron->GetSize();
-  theNewSize = aLength * aSizeInPercents / 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;
-}
-
 double VTKViewer_ViewFrame::GetTrihedronSize() const
 {
   return m_Triedron->GetSize();
 }
 
-void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate )
+void VTKViewer_ViewFrame::AdjustTrihedrons(const bool forced)
 {
   
-  if ( !isCubeAxesDisplayed() && !isTrihedronDisplayed() && !forcedUpdate )
+  if ( (!isCubeAxesDisplayed() || !isTrihedronDisplayed()) && forced)
     return;
 
   float bnd[ 6 ];
@@ -253,11 +213,22 @@ void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate )
         << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
 
   int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
-  if ( aVisibleNum || forcedUpdate )
+  if ( aVisibleNum )
   {
     // if the new trihedron size have sufficient difference, then apply the value
-    double aNewSize = 100, anOldSize;
-    if ( ComputeTrihedronSize( aNewSize, anOldSize ) || forcedUpdate )
+    double aNewSize = 100, anOldSize=m_Triedron->GetSize();
+    
+    m_Triedron->VisibilityOff();
+    m_CubeAxes->VisibilityOff();
+    static float aSizeInPercents = 105;
+    QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
+    if ( !aSetting.isEmpty() )
+      aSizeInPercents = aSetting.toFloat();
+    bool isComputeTrihedronSize = ::ComputeTrihedronSize(m_Renderer, aNewSize, anOldSize, aSizeInPercents);
+    m_Triedron->VisibilityOn();
+    m_CubeAxes->VisibilityOn();
+    
+    if ( isComputeTrihedronSize )
     {
       m_Triedron->SetSize( aNewSize );
       // itearte throuh displayed objects and set size if necessary
@@ -307,37 +278,35 @@ void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate )
   ::ResetCameraClippingRange(m_Renderer);
 }
 
-void VTKViewer_ViewFrame::AdjustAxes( const bool forcedUpdate )
-{
-  AdjustTrihedrons(forcedUpdate);
-}
-
 void VTKViewer_ViewFrame::onAdjustTrihedron()
-{   
-  AdjustTrihedrons( false );
+{
+  AdjustTrihedrons(false);
 }
 
-void VTKViewer_ViewFrame::onAdjustAxes()
+void VTKViewer_ViewFrame::onAdjustCubeAxes()
 {   
-  AdjustAxes( false );
+  AdjustTrihedrons(false);
 }
 
 /*!
   Display/hide Trihedron
 */
 void VTKViewer_ViewFrame::onViewTrihedron(){
+  onViewCubeAxes();
   if(!m_Triedron) return;
-  if(isTrihedronDisplayed()){
-    m_Triedron->VisibilityOff();
-    m_CubeAxes->VisibilityOff();
-  }
-  else{
-    m_Triedron->VisibilityOn();
-    m_CubeAxes->VisibilityOn();
-  }
+  if(isTrihedronDisplayed()) m_Triedron->VisibilityOff();
+  else m_Triedron->VisibilityOn();
   Repaint();
 }
 
+void VTKViewer_ViewFrame::onViewCubeAxes(){
+  if(!m_CubeAxes) return;
+  if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff();
+  else m_CubeAxes->VisibilityOn();
+  Repaint();
+}
+
+
 /*!
   Provides top projection of the active view
 */
@@ -412,11 +381,11 @@ void VTKViewer_ViewFrame::onViewFitAll(){
   int aTriedronWasVisible = false;
   int aCubeAxesWasVisible = false;
   if(m_Triedron){
-    aTriedronWasVisible = m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+    aTriedronWasVisible = isTrihedronDisplayed();
     if(aTriedronWasVisible) m_Triedron->VisibilityOff();
   }
   if(m_CubeAxes){
-    aCubeAxesWasVisible = m_CubeAxes->GetVisibility();
+    aCubeAxesWasVisible = isCubeAxesDisplayed();
     if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
   }
 
@@ -443,21 +412,23 @@ void VTKViewer_ViewFrame::onViewFitAll(){
 */
 void VTKViewer_ViewFrame::onViewReset(){
   int aTriedronIsVisible = isTrihedronDisplayed();
+  int aCubeAxesIsVisible = isCubeAxesDisplayed();
+  
   m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
-  m_CubeAxes->SetVisibility(2);
+  m_CubeAxes->SetVisibility(0);
+  
   ::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();
-    m_CubeAxes->VisibilityOn();
-  }
-  else{
-    m_Triedron->VisibilityOff();
-    m_CubeAxes->VisibilityOff();
-  }
+  
+  if(aTriedronIsVisible) m_Triedron->VisibilityOn();
+  else m_Triedron->VisibilityOff();
+  
+  if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn();
+  else m_CubeAxes->VisibilityOff();
+
   static float aCoeff = 3.0;
   aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
   Repaint();
@@ -724,9 +695,10 @@ void VTKViewer_ViewFrame::EraseAll()
 }
 
 
-void VTKViewer_ViewFrame::Repaint(bool theUpdateAxes)
+void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
 {
-  if (theUpdateAxes) onAdjustAxes();
+  if (theUpdateTrihedron) onAdjustTrihedron();
+  //if (theUpdateCubeAxes) onAdjustCubeAxes();
   m_RW->update();
 }
 
@@ -935,9 +907,6 @@ void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theTo
   if ( aComponent->_is_nil() )
     return;
 
-//   bool isTrhDisplayed = isTrihedronDisplayed();
-//   bool isCubeDisplayed = isCubeAxesDisplayed();
-
   m_RWInteractor->RemoveAll( false );
   //m_RWInteractor->EraseAll();
 
index 6efcf6a5b65e18128f66a5336692683a58f0ed71..2ece831dcaec3baa01613433d88cee9df95b9443 100644 (file)
@@ -109,10 +109,6 @@ public:
   void                              RemoveActor(SALOME_Actor*, bool update = false);
 
   void                              AdjustTrihedrons( const bool forced );
-  void                              AdjustAxes( const bool forced );
-  
-  bool                              ComputeTrihedronSize( double& theNewSize,
-                                                          double& theOldSize );
   double                            GetTrihedronSize() const;
 
   VTKViewer_Trihedron*              GetTrihedron() {return this->m_Triedron;};
@@ -132,9 +128,11 @@ public slots:
   void                              onViewLeft();     
   void                              onViewBottom();
   void                              onViewTop();
-  void                              onViewTrihedron(); 
+  void                              onViewTrihedron();
+  void                              onViewCubeAxes();
+
   void                              onAdjustTrihedron();
-  void                              onAdjustAxes();
+  void                              onAdjustCubeAxes();
  
   void                              onPanLeft();
   void                              onPanRight();